Skip to content Skip to sidebar Skip to footer

JSONException When Parse A Valid Json

I try to parse this valid JSON I use new JSONObject(resultString); but i have JSONException How can i parse his Json Help me please! Thanks [{ 'id': '8637F7F78C8C1', 'fro

Solution 1:

it's a JSONArray not a JSONObject ..
JSON Array iteration in Android/Java

JSONArray values = new JSONArray(resultString);
for(int i = 0 ; i < values.length(); i++){
    JSONObject object = (JSONObject) values.get(i); 
    String id = object.getString("id");
    //the same for the rest
}

Solution 2:

That's not a JSON object - it's a JSON array containing two objects.

Use new JSONArray(resultString); first then get the objects from that.


Solution 3:

Hi [] denotes array in JSON, so after parsing try to put it in JSONArray... new JSONArray(resultString).getJSONObject(int index);

in this manner you can get JSON Object..


Solution 4:

For parsing JSON I used GSON.

JsonElement jelement = new JsonParser().parse("json text");

JsonArray array = jobject.getAsJsonArray("myarray");
for (JsonElement item : array) {...}


Post a Comment for "JSONException When Parse A Valid Json"