Retrofit 2, same name different data type JSON Parsing

后端 未结 3 1436
时光取名叫无心
时光取名叫无心 2020-12-03 19:40

I am trying to parse a JSON response from a server, If there are changes to in the query sent in post method I will get first one as response, if not I will get the second o

3条回答
  •  伪装坚强ぢ
    2020-12-03 19:51

    try this,

    try {
            // "data" returns an object
            JSONObject jsonObjectData = jsonObject.getJSONObject("data");
            //rest of your code
        } catch (JSONException e){
            //"data" returns a string
            e.printStackTrace();
            try {
                String data = jsonObject.getString("data");
            } catch (JSONException e1) {
                e1.printStackTrace();
            }
        }
    

提交回复
热议问题