I think the problem you are facing is similar to my own, which I have encountered. If you run:
String json_string = EntityUtils.toString (response.getEntity ());
JSONObject temp1 = new JSONObject (json_string);
The above code throws an exception and it looks like the brackets of the JSON array are to blame. But itβs great that the JSON array is a top-level element! You just need to use JSONArray () instead of JSONObject:
String json_string = EntityUtils.toString (response.getEntity ());
JSONArray temp1 = new JSONArray (json_string);
So you should know if you get a JSONArray or a single dictionary, which is a JSONObject in the JSON code.
If you are used to iOS / Objective-C JSON parsing libraries, they use the same top-level element to work with json dictionaries and json arrays, so the transition to the JAVA / Android world confused me in that I have two types to handle JSON depending on the top level returned.
MikeN Mar 25 '14 at 3:16 2014-03-25 03:16
source share