Example usage for com.google.gson.stream JsonReader endArray

List of usage examples for com.google.gson.stream JsonReader endArray

Introduction

In this page you can find the example usage for com.google.gson.stream JsonReader endArray.

Prototype

public void endArray() throws IOException 

Source Link

Document

Consumes the next token from the JSON stream and asserts that it is the end of the current array.

Usage

From source file:nectec.thai.widget.address.repository.JsonParser.java

License:Apache License

public static <T> List<T> parse(Context context, String jsonFileName, Class<T> tClass) {
    List<T> allProvince = new ArrayList<>();
    Gson gson = new Gson();
    try {/*  w  w w .jav  a2s.  co m*/
        InputStream inputStream = context.getAssets().open(jsonFileName);
        JsonReader reader = new JsonReader(new InputStreamReader(inputStream, "UTF-8"));
        reader.beginArray();
        while (reader.hasNext()) {
            T message = gson.fromJson(reader, tClass);
            allProvince.add(message);
        }
        reader.endArray();
        reader.close();
    } catch (IOException e) {
        if (BuildConfig.DEBUG)
            Log.e(TAG, "parse() error.", e);
    }
    return allProvince;
}

From source file:net.evecom.android.EventAddActivity.java

License:Open Source License

/**
 * getTreeOne// w w  w .  j ava 2s  .co  m
 */
private void getTreeOne(final String sbd_id) {
    progressDialog_getInfo = ProgressDialog.show(EventAddActivity.this, "", "...");
    list.removeAll(list);
    new Thread(new Runnable() {
        @Override
        public void run() {
            Message msg_listData = new Message();
            String strUrl = HttpUtil.BASE_URL + "teventAndroid/queryChildTree?pid=" + "0";
            String strResult = null;
            try {
                strResult = connServerForResult(strUrl);
            } catch (Exception e) {
                msg_listData.what = MESSAGETYPE_02;
                handler1.sendMessage(msg_listData);
                if (null != e) {
                    e.printStackTrace();
                }
                return;
            }
            // DialogToast(strResult);
            // System.out.println(strResult);
            if (null == strResult || "".equals(strResult)) {
                msg_listData.what = MESSAGETYPE_02;
                handler1.sendMessage(msg_listData);
                return;
            }
            StringReader reader = new StringReader(strResult);
            JsonReader jsonReader = new JsonReader(reader);
            try {
                jsonReader.beginArray();
                while (jsonReader.hasNext()) {
                    jsonReader.beginObject();
                    SysBaseDict dict = new SysBaseDict();
                    while (jsonReader.hasNext()) {
                        String nextName = jsonReader.nextName();
                        String nextValue = "";
                        if (nextName.equals("id")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdCode(nextValue);
                        } else if (nextName.equals("name")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdName(nextValue);
                        } else if (nextName.equals("isparent")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdType(nextValue);
                        } else if (nextName.equals("pid")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdPid(nextValue);
                        } else if (nextName.equals("type")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdType(nextValue);
                        }

                        // System.out.println(nextName+"="+nextValue);
                    }
                    list.add(dict);
                    dict = null;
                    jsonReader.endObject();

                }
                jsonReader.endArray();
            } catch (IOException e) {
                if (null != e) {
                    e.printStackTrace();
                }
            }
            if (null == list || list.size() < 1) {
                msg_listData.what = MESSAGETYPE_02;
            } else {
                msg_listData.what = MESSAGETYPE_01;
            }
            handler1.sendMessage(msg_listData);
        }
    }).start();

}

From source file:net.evecom.android.EventAddActivity.java

License:Open Source License

/**
 * getTreeTwo/*w w w  . ja  va2s.c o  m*/
 */
private void getTreeTwo(final String oneStr) {
    progressDialog_getInfo = ProgressDialog.show(EventAddActivity.this, "", "...");
    list.removeAll(list);
    final Message msg_listData = new Message();

    new Thread(new Runnable() {
        @Override
        public void run() {
            String strUrl = HttpUtil.BASE_URL + "teventAndroid/queryChildTree?pid=" + oneStr;
            String strResult = null;
            try {
                strResult = connServerForResult(strUrl);
            } catch (Exception e) {
                msg_listData.what = MESSAGETYPE_02;
                handler2.sendMessage(msg_listData);
                if (null != e) {
                    e.printStackTrace();
                }
                return;
            }
            // DialogToast(strResult);
            // System.out.println(strResult);
            if (null == strResult || "".equals(strResult)) {
                msg_listData.what = MESSAGETYPE_02;
                handler2.sendMessage(msg_listData);
                return;
            }
            StringReader reader = new StringReader(strResult);
            JsonReader jsonReader = new JsonReader(reader);

            try {
                jsonReader.beginArray();
                while (jsonReader.hasNext()) {
                    jsonReader.beginObject();
                    SysBaseDict dict = new SysBaseDict();
                    while (jsonReader.hasNext()) {
                        String nextName = jsonReader.nextName();
                        String nextValue = "";
                        if (nextName.equals("id")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdCode(nextValue);
                        } else if (nextName.equals("name")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdName(nextValue);
                        } else if (nextName.equals("isparent")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdType(nextValue);
                        } else if (nextName.equals("pid")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdPid(nextValue);
                        } else if (nextName.equals("type")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdType(nextValue);
                        }
                        // System.out.println(nextName+"="+nextValue);
                    }
                    list.add(dict);
                    dict = null;
                    jsonReader.endObject();

                }
                jsonReader.endArray();
            } catch (IOException e) {
                if (null != e) {
                    e.printStackTrace();
                }
            }
            if (null == list || list.size() < 1) {
                msg_listData.what = MESSAGETYPE_02;
            } else {
                msg_listData.what = MESSAGETYPE_01;
            }
            handler2.sendMessage(msg_listData);
        }
    }).start();

}

From source file:net.evecom.android.EventAddActivity.java

License:Open Source License

/**
 * getTreeThree/*  w ww  . jav  a2  s .co  m*/
 */
private void getTreeThree(final String sbd_id) {
    progressDialog_getInfo = ProgressDialog.show(EventAddActivity.this, "", "...");
    list.removeAll(list);
    final Message msg_listData = new Message();

    new Thread(new Runnable() {
        @Override
        public void run() {
            String strUrl = HttpUtil.BASE_URL + "teventAndroid/queryChildTree?pid=" + sbd_id;
            String strResult = null;
            try {
                strResult = connServerForResult(strUrl);
            } catch (Exception e) {
                msg_listData.what = MESSAGETYPE_02;
                handler3.sendMessage(msg_listData);
                if (null != e) {
                    e.printStackTrace();
                }
                return;
            }
            if (null == strResult || "".equals(strResult)) {
                msg_listData.what = MESSAGETYPE_02;
                handler3.sendMessage(msg_listData);
                return;
            }
            // System.out.println(strResult);
            StringReader reader = new StringReader(strResult);
            JsonReader jsonReader = new JsonReader(reader);

            try {
                jsonReader.beginArray();
                while (jsonReader.hasNext()) {
                    jsonReader.beginObject();
                    SysBaseDict dict = new SysBaseDict();
                    while (jsonReader.hasNext()) {
                        String nextName = jsonReader.nextName();
                        String nextValue = "";
                        if (nextName.equals("id")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdCode(nextValue);
                        } else if (nextName.equals("name")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdName(nextValue);
                        } else if (nextName.equals("isparent")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdType(nextValue);
                        } else if (nextName.equals("pid")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdPid(nextValue);
                        } else if (nextName.equals("type")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdType(nextValue);
                        }
                    }
                    list.add(dict);
                    dict = null;
                    jsonReader.endObject();
                }
                jsonReader.endArray();
            } catch (IOException e) {
                if (null != e) {
                    e.printStackTrace();
                }
            }
            if (null == list || list.size() < 1) {
                msg_listData.what = MESSAGETYPE_02;
            } else {
                msg_listData.what = MESSAGETYPE_01;
            }
            handler3.sendMessage(msg_listData);
        }
    }).start();

}

From source file:net.evecom.android.EventAddActivity1.java

License:Open Source License

/**
 * getTreeOne//from  www . ja  v  a  2  s  . co m
 */
private void getTreeOne(final String sbd_id) {
    progressDialog_getInfo = ProgressDialog.show(EventAddActivity1.this, "", "...");
    list.removeAll(list);
    new Thread(new Runnable() {
        @Override
        public void run() {
            Message msg_listData = new Message();
            String strUrl = HttpUtil.BASE_URL + "teventAndroid/queryChildTree?pid=" + "0";
            String strResult = null;
            try {
                strResult = connServerForResult(strUrl);
            } catch (Exception e) {
                msg_listData.what = MESSAGETYPE_02;
                handler1.sendMessage(msg_listData);
                if (null != e) {
                    e.printStackTrace();
                }
                return;
            }
            // DialogToast(strResult);
            // System.out.println(strResult);
            if (null == strResult || "".equals(strResult)) {
                msg_listData.what = MESSAGETYPE_02;
                handler1.sendMessage(msg_listData);
                return;
            }
            StringReader reader = new StringReader(strResult);
            JsonReader jsonReader = new JsonReader(reader);
            try {
                jsonReader.beginArray();
                while (jsonReader.hasNext()) {
                    jsonReader.beginObject();
                    SysBaseDict dict = new SysBaseDict();
                    while (jsonReader.hasNext()) {
                        String nextName = jsonReader.nextName();
                        String nextValue = "";
                        if (nextName.equals("id")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdCode(nextValue);
                        } else if (nextName.equals("name")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdName(nextValue);
                        } else if (nextName.equals("isparent")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdType(nextValue);
                        } else if (nextName.equals("pid")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdPid(nextValue);
                        } else if (nextName.equals("type")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdType(nextValue);
                        }

                        // System.out.println(nextName+"="+nextValue);
                    }
                    list.add(dict);
                    dict = null;
                    jsonReader.endObject();

                }
                jsonReader.endArray();
            } catch (IOException e) {
                if (null != e) {
                    e.printStackTrace();
                }
            }
            if (null == list || list.size() < 1) {
                msg_listData.what = MESSAGETYPE_02;
            } else {
                msg_listData.what = MESSAGETYPE_01;
            }
            handler1.sendMessage(msg_listData);
        }
    }).start();

}

From source file:net.evecom.android.EventAddActivity1.java

License:Open Source License

/**
 * getTreeTwo/*from w  ww .ja  v a 2s  . c o  m*/
 */
private void getTreeTwo(final String oneStr) {
    progressDialog_getInfo = ProgressDialog.show(EventAddActivity1.this, "", "...");
    list.removeAll(list);
    final Message msg_listData = new Message();

    new Thread(new Runnable() {
        @Override
        public void run() {
            String strUrl = HttpUtil.BASE_URL + "teventAndroid/queryChildTree?pid=" + oneStr;
            String strResult = null;
            try {
                strResult = connServerForResult(strUrl);
            } catch (Exception e) {
                msg_listData.what = MESSAGETYPE_02;
                handler2.sendMessage(msg_listData);
                if (null != e) {
                    e.printStackTrace();
                }
                return;
            }
            // DialogToast(strResult);
            // System.out.println(strResult);
            if (null == strResult || "".equals(strResult)) {
                msg_listData.what = MESSAGETYPE_02;
                handler2.sendMessage(msg_listData);
                return;
            }
            StringReader reader = new StringReader(strResult);
            JsonReader jsonReader = new JsonReader(reader);

            try {
                jsonReader.beginArray();
                while (jsonReader.hasNext()) {
                    jsonReader.beginObject();
                    SysBaseDict dict = new SysBaseDict();
                    while (jsonReader.hasNext()) {
                        String nextName = jsonReader.nextName();
                        String nextValue = "";
                        if (nextName.equals("id")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdCode(nextValue);
                        } else if (nextName.equals("name")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdName(nextValue);
                        } else if (nextName.equals("isparent")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdType(nextValue);
                        } else if (nextName.equals("pid")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdPid(nextValue);
                        } else if (nextName.equals("type")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdType(nextValue);
                        }
                        // System.out.println(nextName+"="+nextValue);
                    }
                    list.add(dict);
                    dict = null;
                    jsonReader.endObject();

                }
                jsonReader.endArray();
            } catch (IOException e) {
                if (null != e) {
                    e.printStackTrace();
                }
            }
            if (null == list || list.size() < 1) {
                msg_listData.what = MESSAGETYPE_02;
            } else {
                msg_listData.what = MESSAGETYPE_01;
            }
            handler2.sendMessage(msg_listData);
        }
    }).start();

}

From source file:net.evecom.android.EventAddActivity1.java

License:Open Source License

/**
 * getTreeThree//from   w  ww .j a  v  a2s.  com
 */
private void getTreeThree(final String sbd_id) {
    progressDialog_getInfo = ProgressDialog.show(EventAddActivity1.this, "", "...");
    list.removeAll(list);
    final Message msg_listData = new Message();

    new Thread(new Runnable() {
        @Override
        public void run() {
            String strUrl = HttpUtil.BASE_URL + "teventAndroid/queryChildTree?pid=" + sbd_id;
            String strResult = null;
            try {
                strResult = connServerForResult(strUrl);
            } catch (Exception e) {
                msg_listData.what = MESSAGETYPE_02;
                handler3.sendMessage(msg_listData);
                if (null != e) {
                    e.printStackTrace();
                }
                return;
            }
            if (null == strResult || "".equals(strResult)) {
                msg_listData.what = MESSAGETYPE_02;
                handler3.sendMessage(msg_listData);
                return;
            }
            // System.out.println(strResult);
            StringReader reader = new StringReader(strResult);
            JsonReader jsonReader = new JsonReader(reader);

            try {
                jsonReader.beginArray();
                while (jsonReader.hasNext()) {
                    jsonReader.beginObject();
                    SysBaseDict dict = new SysBaseDict();
                    while (jsonReader.hasNext()) {
                        String nextName = jsonReader.nextName();
                        String nextValue = "";
                        if (nextName.equals("id")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdCode(nextValue);
                        } else if (nextName.equals("name")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdName(nextValue);
                        } else if (nextName.equals("isparent")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdType(nextValue);
                        } else if (nextName.equals("pid")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdPid(nextValue);
                        } else if (nextName.equals("type")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdType(nextValue);
                        }
                    }
                    list.add(dict);
                    dict = null;
                    jsonReader.endObject();
                }
                jsonReader.endArray();
            } catch (IOException e) {
                if (null != e) {
                    e.printStackTrace();
                }
            }
            if (null == list || list.size() < 1) {
                msg_listData.what = MESSAGETYPE_02;
            } else {
                msg_listData.what = MESSAGETYPE_01;
            }
            handler3.sendMessage(msg_listData);
        }
    }).start();

}

From source file:net.evecom.android.json.JsonMainPersonKeyPersonData.java

License:Open Source License

public static ArrayList<T_PERSON_PERSON> getData(final String path, String entity_str) throws Exception {
    URL url = new URL(path);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("POST");
    byte[] entity = entity_str.getBytes();
    conn.setConnectTimeout(5000);/*from ww w.j  av a 2 s .c om*/
    conn.setDoOutput(true);
    conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    conn.setRequestProperty("Content-Length", String.valueOf(entity.length));
    conn.getOutputStream().write(entity);
    if (conn.getResponseCode() == 200) {
        InputStream inputstream = conn.getInputStream();
        StringBuffer buffer = new StringBuffer();
        byte[] b = new byte[1024];
        for (int i; (i = inputstream.read(b)) != -1;) {
            buffer.append(new String(b, 0, i));
        }
        StringReader reader = new StringReader(buffer.toString());
        JsonReader jsonReader = new JsonReader(reader);
        list = new ArrayList<T_PERSON_PERSON>();

        jsonReader.beginArray();
        while (jsonReader.hasNext()) {
            jsonReader.beginObject();
            T_PERSON_PERSON person_view = new T_PERSON_PERSON();
            while (jsonReader.hasNext()) {
                String nextName = jsonReader.nextName();
                String nextValue = "";
                if (nextName.equals("PERSONNAME")) {
                    nextValue = jsonReader.nextString();
                    person_view.setPERSONNAME(nextValue);
                } else if (nextName.equals("PERSONPHONENO")) {
                    nextValue = jsonReader.nextString();
                    person_view.setPERSONPHONENO(nextValue);
                } else if (nextName.equals("PHOTOURL")) {
                    nextValue = jsonReader.nextString();
                    person_view.setPHOTOURL(nextValue);
                } else if (nextName.equals("KEYTYPE")) {
                    nextValue = jsonReader.nextString();
                    person_view.setKEYTYPE(nextValue);
                } else if (nextName.equals("HOUSEADDR")) {
                    nextValue = jsonReader.nextString();
                    person_view.setHOUSEADDR(nextValue);
                } else if (nextName.equals("IDCARDNO")) {
                    nextValue = jsonReader.nextString();
                    person_view.setIDCARDNO(nextValue);
                } else if (nextName.equals("MALEDICTID")) {
                    nextValue = jsonReader.nextString();
                    person_view.setMALEDICTID(nextValue);
                } else if (nextName.equals("PERSONID")) {
                    nextValue = jsonReader.nextString();
                    person_view.setPERSONID(nextValue);
                }
            }
            list.add(person_view);
            person_view = null;
            jsonReader.endObject();
        }
        jsonReader.endArray();
        return list;
    } else {
        return null;
    }
}

From source file:net.evecom.android.json.JsonMainPersonViewData.java

License:Open Source License

public static ArrayList<T_PERSON_INTERVIEW> getData(final String path, String entity_str) throws Exception {

    URL url = new URL(path);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("POST");
    byte[] entity = entity_str.getBytes();
    conn.setConnectTimeout(5000);/*from   w ww .  ja v a 2s . c o m*/
    conn.setDoOutput(true);
    conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    conn.setRequestProperty("Content-Length", String.valueOf(entity.length));
    conn.getOutputStream().write(entity);
    if (conn.getResponseCode() == 200) {
        InputStream inputstream = conn.getInputStream();
        StringBuffer buffer = new StringBuffer();
        byte[] b = new byte[1024];
        for (int i; (i = inputstream.read(b)) != -1;) {
            buffer.append(new String(b, 0, i));
        }
        StringReader reader = new StringReader(buffer.toString());
        JsonReader jsonReader = new JsonReader(reader);
        list = new ArrayList<T_PERSON_INTERVIEW>();
        jsonReader.beginArray();
        while (jsonReader.hasNext()) {
            jsonReader.beginObject();
            T_PERSON_INTERVIEW person_view = new T_PERSON_INTERVIEW();
            while (jsonReader.hasNext()) {
                String nextName = jsonReader.nextName();
                String nextValue = "";
                if (nextName.equals("INTERVIEWEFFECT")) {
                    nextValue = jsonReader.nextString();
                    person_view.setINTERVIEWEFFECT(nextValue);
                } else if (nextName.equals("PERSONNAME")) {
                    nextValue = jsonReader.nextString();
                    person_view.setPERSONNAME(nextValue);
                } else if (nextName.equals("INTERVIEWTIME")) {
                    nextValue = jsonReader.nextString();
                    person_view.setINTERVIEWTIME(nextValue);
                } else if (nextName.equals("INTERVIEWID")) {
                    nextValue = jsonReader.nextString();
                    person_view.setINTERVIEWID(nextValue);
                } else if (nextName.equals("INTERVIEWTYPE")) {
                    nextValue = jsonReader.nextString();
                    person_view.setINTERVIEWTYPE(nextValue);
                } else if (nextName.equals("BIRTH")) {
                    nextValue = jsonReader.nextString();
                    person_view.setBIRTH(nextValue);
                } else if (nextName.equals("MALEDICTID")) {
                    nextValue = jsonReader.nextString();
                    person_view.setMALEDICTID(nextValue);
                } else if (nextName.equals("PERSONID")) {
                    nextValue = jsonReader.nextString();
                    person_view.setPERSONID(nextValue);
                }
            }
            list.add(person_view);
            person_view = null;
            jsonReader.endObject();
        }
        jsonReader.endArray();
        return list;
    } else {
        return null;
    }
}

From source file:net.evecom.android.json.JsonMainPlaceKeyPlaceData.java

License:Open Source License

public static ArrayList<T_PLACE_PLACE> getData(final String path, String entity_str) throws Exception {
    URL url = new URL(path);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("POST");
    byte[] entity = entity_str.getBytes();
    conn.setConnectTimeout(5000);//from w w  w . jav  a2 s.  c om
    conn.setDoOutput(true);
    conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    conn.setRequestProperty("Content-Length", String.valueOf(entity.length));
    conn.getOutputStream().write(entity);
    if (conn.getResponseCode() == 200) {
        InputStream inputstream = conn.getInputStream();
        StringBuffer buffer = new StringBuffer();
        byte[] b = new byte[1024];
        for (int i; (i = inputstream.read(b)) != -1;) {
            buffer.append(new String(b, 0, i));
        }
        StringReader reader = new StringReader(buffer.toString());
        JsonReader jsonReader = new JsonReader(reader);
        list = new ArrayList<T_PLACE_PLACE>();
        jsonReader.beginArray();
        while (jsonReader.hasNext()) {
            jsonReader.beginObject();
            T_PLACE_PLACE person_view = new T_PLACE_PLACE();
            while (jsonReader.hasNext()) {
                String nextName = jsonReader.nextName();
                String nextValue = "";
                if (nextName.equals("PLACEADDR")) {
                    nextValue = jsonReader.nextString();
                    person_view.setPLACEADDR(nextValue);
                } else if (nextName.equals("PLACETYPED")) {
                    nextValue = jsonReader.nextString();
                    person_view.setPLACETYPED(nextValue);
                } else if (nextName.equals("PLACENAME")) {
                    nextValue = jsonReader.nextString();
                    person_view.setPLACENAME(nextValue);
                } else if (nextName.equals("PLACEID")) {
                    nextValue = jsonReader.nextString();
                    person_view.setPLACEID(nextValue);
                }
            }
            list.add(person_view);
            person_view = null;
            jsonReader.endObject();
        }
        jsonReader.endArray();
        return list;
    } else {
        return null;
    }
}