Value of type org.json.JSONArray cannot be converted to JSONObject

后端 未结 2 1579
南旧
南旧 2021-02-13 17:56

Got stuck at this error:

3169-3190/com.meisolsson.app E/JSON Parser﹕ Error parsing data org.json.JSONException: Value [{\"type\":0,\"can_see_custom_stori

2条回答
  •  爱一瞬间的悲伤
    2021-02-13 18:50

    Even though I had a single JSON object it was stored in an array as Hariharan has pointed out with the square brackets [ { items:items, ... } ]

    My solution was simply to parse out the only object, located in array position [0] like this

    JSONArray jsonArray = new JSONArray(stringIn);
    
    JSONObject obj = jsonArray.getJSONObject(0);
    

提交回复
热议问题