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

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

Introduction

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

Prototype

public void endObject() throws IOException 

Source Link

Document

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

Usage

From source file:io.github.rcarlosdasilva.weixin.core.json.adapter.OpenPlatformAuthGetLicenseInformationResponseTypeAdapter.java

private void readBusinessInfo(JsonReader in, LicensorInfromation licensorInfromation) throws IOException {
    in.beginObject();/*  www.  j a  v  a2  s.  c  om*/
    while (in.hasNext()) {
        String key = in.nextName();
        switch (key) {
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_STORE_KEY:
            licensorInfromation.setBusinessStoreOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER);
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_SCAN_KEY:
            licensorInfromation.setBusinessScanOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER);
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_PAY_KEY:
            licensorInfromation.setBusinessPayOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER);
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_CARD_KEY:
            licensorInfromation.setBusinessCardOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER);
            break;
        case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_SHAKE_KEY:
            licensorInfromation.setBusinessShakeOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER);
            break;
        default:
            if (in.hasNext()) {
                String value = in.nextString();
                logger.warn(LOG_UNKNOWN_JSON_KEY, key, value);
            }
        }
    }
    in.endObject();
}

From source file:io.grpc.internal.JsonParser.java

License:Apache License

private static Map<String, ?> parseJsonObject(JsonReader jr) throws IOException {
    jr.beginObject();// ww  w .j a v a  2s .  c om
    Map<String, Object> obj = new LinkedHashMap<>();
    while (jr.hasNext()) {
        String name = jr.nextName();
        Object value = parseRecursive(jr);
        obj.put(name, value);
    }
    checkState(jr.peek() == JsonToken.END_OBJECT, "Bad token: " + jr.getPath());
    jr.endObject();
    return Collections.unmodifiableMap(obj);
}

From source file:io.prediction.workflow.JavaQueryTypeAdapterFactory.java

License:Apache License

@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    if (type.getRawType().equals(JavaQuery.class)) {
        return (TypeAdapter<T>) new TypeAdapter<JavaQuery>() {
            public void write(JsonWriter out, JavaQuery value) throws IOException {
                if (value == null) {
                    out.nullValue();/*  w  ww  . j a  va2s.c o  m*/
                } else {
                    out.beginObject();
                    out.name("q").value(value.getQ().toUpperCase());
                    out.endObject();
                }
            }

            public JavaQuery read(JsonReader reader) throws IOException {
                if (reader.peek() == JsonToken.NULL) {
                    reader.nextNull();
                    return null;
                } else {
                    reader.beginObject();
                    reader.nextName();
                    String q = reader.nextString();
                    reader.endObject();
                    return new JavaQuery(q.toUpperCase());
                }
            }
        };
    } else {
        return null;
    }
}

From source file:it.bradipao.berengar.DbTool.java

License:Apache License

public static int gson2db(SQLiteDatabase mDB, File jsonFile) {

    // vars//from ww w.  j a  v  a  2 s  .  c om
    int iTableNum = 0;
    FileReader fr = null;
    BufferedReader br = null;
    JsonReader jr = null;
    String name = null;
    String val = null;

    String mTable = null;
    String mTableSql = null;
    ArrayList<String> aFields = null;
    ArrayList<String> aValues = null;
    ContentValues cv = null;

    // file readers
    try {
        fr = new FileReader(jsonFile);
        br = new BufferedReader(fr);
        jr = new JsonReader(br);
    } catch (FileNotFoundException e) {
        Log.e(LOGTAG, "error in gson2db file readers", e);
    }

    // parsing
    try {
        // start database transaction
        mDB.beginTransaction();
        // open root {
        jr.beginObject();
        // iterate through root objects
        while (jr.hasNext()) {
            name = jr.nextName();
            if (jr.peek() == JsonToken.NULL)
                jr.skipValue();
            // number of tables
            else if (name.equals("tables_num")) {
                val = jr.nextString();
                iTableNum = Integer.parseInt(val);
                if (GOLOG)
                    Log.d(LOGTAG, "TABLE NUM : " + iTableNum);
            }
            // iterate through tables array
            else if (name.equals("tables")) {
                jr.beginArray();
                while (jr.hasNext()) {
                    // start table
                    mTable = null;
                    aFields = null;
                    jr.beginObject();
                    while (jr.hasNext()) {
                        name = jr.nextName();
                        if (jr.peek() == JsonToken.NULL)
                            jr.skipValue();
                        // table name
                        else if (name.equals("table_name")) {
                            mTable = jr.nextString();
                        }
                        // table sql
                        else if (name.equals("table_sql")) {
                            mTableSql = jr.nextString();
                            if ((mTable != null) && (mTableSql != null)) {
                                mDB.execSQL("DROP TABLE IF EXISTS " + mTable);
                                mDB.execSQL(mTableSql);
                                if (GOLOG)
                                    Log.d(LOGTAG, "DROPPED AND CREATED TABLE : " + mTable);
                            }
                        }
                        // iterate through columns name
                        else if (name.equals("cols_name")) {
                            jr.beginArray();
                            while (jr.hasNext()) {
                                val = jr.nextString();
                                if (aFields == null)
                                    aFields = new ArrayList<String>();
                                aFields.add(val);
                            }
                            jr.endArray();
                            if (GOLOG)
                                Log.d(LOGTAG, "COLUMN NAME : " + aFields.toString());
                        }
                        // iterate through rows
                        else if (name.equals("rows")) {
                            jr.beginArray();
                            while (jr.hasNext()) {
                                jr.beginArray();
                                // iterate through values in row
                                aValues = null;
                                cv = null;
                                while (jr.hasNext()) {
                                    val = jr.nextString();
                                    if (aValues == null)
                                        aValues = new ArrayList<String>();
                                    aValues.add(val);
                                }
                                jr.endArray();
                                // add to database
                                cv = new ContentValues();
                                for (int j = 0; j < aFields.size(); j++)
                                    cv.put(aFields.get(j), aValues.get(j));
                                mDB.insert(mTable, null, cv);
                                if (GOLOG)
                                    Log.d(LOGTAG, "INSERT IN " + mTable + " : " + aValues.toString());
                            }
                            jr.endArray();
                        } else
                            jr.skipValue();
                    }
                    // end table
                    jr.endObject();
                }
                jr.endArray();
            } else
                jr.skipValue();
        }
        // close root }
        jr.endObject();
        jr.close();
        // successfull transaction
        mDB.setTransactionSuccessful();
    } catch (IOException e) {
        Log.e(LOGTAG, "error in gson2db gson parsing", e);
    } finally {
        mDB.endTransaction();
    }

    return iTableNum;
}

From source file:me.ixfan.wechatkit.message.out.json.MassMessageGsonTypeAdapter.java

License:Open Source License

@Override
public MessageForMassSend read(JsonReader in) throws IOException {
    MessageForMassSend.Filter filter = null;
    List<String> toUser = null;
    String msgType = null;//from www .ja va 2s .  c om
    String msgContent = null;

    in.beginObject();
    while (in.hasNext()) {
        switch (in.nextName()) {
        case "msgtype":
            msgType = in.nextString();
            break;
        case "filter":
            in.beginObject();
            String tagId = null;
            boolean isToAll = false;
            while (in.hasNext()) {
                switch (in.nextName()) {
                case "is_to_all":
                    isToAll = in.nextBoolean();
                    break;
                case "tag_id":
                    tagId = in.nextString();
                    break;
                default:
                    break;
                }
            }
            in.endObject();
            filter = new MessageForMassSend.Filter(tagId, isToAll);
            break;
        case "touser":
            in.beginArray();
            toUser = new ArrayList<>();
            while (in.hasNext()) {
                toUser.add(in.nextString());
            }
            in.endArray();
            break;
        case "text":
        case "image":
        case "voice":
        case "mpnews":
        case "mpvideo":
        case "wxcard":
            in.beginObject();
            while (in.hasNext()) {
                switch (in.nextName()) {
                case "content":
                case "media_id":
                case "card_id":
                    msgContent = in.nextString();
                    break;
                default:
                    break;
                }
            }
            in.endObject();
            break;
        default:
            break;
        }
    }

    in.endObject();

    if (null != filter) {
        return new MessageForMassSend(OutMessageType.valueOf(msgType), msgContent, filter.getTagId(),
                filter.isToAll());
    } else if (null != toUser) {
        return new MessageForMassSend(OutMessageType.valueOf(msgType), msgContent, toUser);
    }
    return null;
}

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

License:Open Source License

/**
 * getTreeOne//  w  w w.  ja  va 2  s . c  o  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  ww .jav  a2  s . c  om
 */
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//from  w  w w .ja va  2  s. com
 */
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/*www  .jav  a2s  .  c om*/
 */
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  ww  w . j a v  a 2  s .  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();

}