java - org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1] -


iam parsing json using org.json in java . json list like:

 [ { "id": "f187b01b145c4171b66d4a2ecabb8f44" }, { "id": "a5e66b7462e24924a03e89f0619a2398" }, { "id": "2fb3627360db4ab78a0b3f27527b1983" } ] 

i fetch data java code :

jsonobject json = new jsonobject(response.getentity(string.class));                                  jobs[] obj = new gson().fromjson(json.tostring(), jobs[].class); system.out.println(obj.tostring()); 

but gives exception :

exception in thread "main" org.json.jsonexception: jsonobject text must begin '{' @ 1 [character 2 line 1] @ org.json.jsontokener.syntaxerror(jsontokener.java:433) @ org.json.jsonobject.<init>(jsonobject.java:197) @ org.json.jsonobject.<init>(jsonobject.java:324) @ br.usp.icmc.teste.connectionrestclient.getsaucelabsgetjobs(connectionrestclient.java:80) @ br.usp.icmc.teste.testeprincipal.main(testeprincipal.java:9) 

why did not recognized jsonarray ? wrong ?

u can try below code. there many ways it, below 1 of way   jsonarray jsonarray = new jsonarray(response.getentity(string.class));         for(int =0; i< jsonarray.length(); i++){             if(jsonarray.get(i) instanceof jsonobject){                 jsonobject jsnobj = (jsonobject)jsonarray.get(i);                 string finalvalue = (string)jsnobj.get("id");             }         } 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -