android - at 0 of type java.lang.String cannot be converted to JSONArray -
i facing exception @ 0 of type java.lang.string cannot converted jsonarray don't know why? have use before in different work didn't exception
list<namevaluepair> pair = new arraylist<>(); pair.add(new basicnamevaluepair("id", string.valueof(getitemno))); json = jsonparser.makehttprequest("http://192.168.1.51:80/stopviewapi/index.php","post",pair); log.d("route response", json.tostring()); int success = 0; try { success = json.getint(tag_success); routearrray = new arraylist<string>(); } catch (jsonexception e) { e.printstacktrace(); } try { if (success == 1) { jsonarray jsonarray; json = new jsonobject(jsonparser.result); jsonarray jarray = json.getjsonarray("data"); (int = 0; <= jarray.length(); i++) { jsonarray = jarray.getjsonarray(i); stopnames = jsonarray.getstring(0); counter++; if (counter <=jarray.length()) { //routearrray.add(stopnames); log.d("stop name:", stopnames); //log.d("route name:", routearrray.tostring()); } else { break; } }
json url
{ "data":[ "rawat","islamabad mor","kaak pull","lohi bher","koral chowk","gangal", "khana bridge","zia masjid","kuri road","dhok kala khan","faizabad", "pirwadhai mor","tanki stop i-8\/4","i-8\/3 stop","al shifa hospital","aiou", "zero point","children hospital","f-8\/4","ali hospital" ], "success":1, "status":200, "status_message":"login successfull" }
error: @ line
jsonarray = jarray.getjsonarray(i);
from json, jarray
array of string , not array of jsonarray.
replace:
jsonarray = jarray.getjsonarray(i); stopnames = jsonarray.getstring(0);
with:
stopnames = jarray.getstring(i);
Comments
Post a Comment