android - This JSON object cannot be converted to JSON array -
i have tried , can't covert json object json array, throws json exception
here logcat:
11-13 11:19:53.964: w/system.err(8642): @ org.json.json.typemismatch(json.java:111) 11-13 11:19:53.964: w/system.err(8642): @ org.json.jsonarray.(jsonarray.java:91) 11-13 11:19:53.964: w/system.err(8642): @ org.json.jsonarray.(jsonarray.java:103)
here json file:
{"getgisresult":[{"active":true,"categoryid":1,"createdate":null,"createuser":null,"description_ar":"التا","description_en":"هعلل","email":"لتتالت","lat":30.0764857,"long":31.30658,"mobile":"تالتال","sectionid":9,"sectionname_ar":"1","sectionname_en":"لاتا","updatedate":null,"updateuser":null},{"active":true,"categoryid":1,"createdate":null,"createuser":null,"description_ar":"التا","description_en":"هعلل","email":"لتتالت","lat":30.0892124,"long":31.2892342,"mobile":"تالتال","sectionid":10,"sectionname_ar":"2","sectionname_en":"لاتا","updatedate":null,"updateuser":null},{"active":true,"categoryid":1,"createdate":null,"createuser":null,"description_ar":"التا","description_en":"هعلل","email":"لتتالت","lat":30.0433341,"long":31.3006067,"mobile":"تالتال","sectionid":15,"sectionname_ar":"7","sectionname_en":"لاتا","updatedate":null,"updateuser":null}]}
here code:
try { httpresponse response = httpclient.execute(httpget); int responsecode = response.getstatusline().getstatuscode(); if (responsecode == 200) { inputstream in = response.getentity().getcontent(); resultstring = convertinputstreamtostring(in); system.out.println("resultstring>>> "+resultstring); try { jsonarray stores = new jsonarray(resultstring); (int = 0; < stores.length(); ++i) { jsonobject jo = (jsonobject) stores.get(i); // to-do json here result.add(converttostores(jo)); log.v("check on adding lat list", result.get(i) .getlat()+""); log.v("check on adding lon list", result.get(i) .getlong()+""); log.v("check on adding description list", result.get(i).getdescription_ar()); log.v("check on adding email list", result.get(i).getemail()); log.v("check on adding mobile list", result .get(i).getmobile()); } } catch (jsonexception c) { log.v("exception >>>", c.getmessage().tostring()); c.printstacktrace(); } long total = 0; byte data[] = new byte[1024]; while ((count = in.read(data)) != -1) { total += count; // publishing progress.... // after onprogressupdate called setprogress((int)((total*100)/1000)); } }else if(responsecode != 200){ toast.maketext(getapplicationcontext(), "your connection break down please check connection ..", toast.length_long).show(); } public static string convertinputstreamtostring(inputstream ists) throws ioexception { if (ists != null) { stringbuilder sb = new stringbuilder(); string line; try { bufferedreader r1 = new bufferedreader(new inputstreamreader( ists, "utf-8")); while ((line = r1.readline()) != null) { sb.append(line).append("\n"); } } { ists.close(); } return sb.tostring(); } else { return ""; } }
first have create jsonobject result.
jsonobject jsonobj=new jsonobject(resultstring); jsonarray array=jsonobj.getjsonarray("getgisresult");
Comments
Post a Comment