android - Looping through JSONObject to Create Array Java -
i have jsonobject
of following format:
[{"ascii_name":"rio de janeiro"},{"ascii_name":"riyadh"},{"ascii_name":"rome"},{"ascii_name":"rawalpindi"},{"ascii_name":"rabat"},{"ascii_name":"recife"},{"ascii_name":"ra's bayrut"},{"ascii_name":"rajkot"}]
which has been created using following code:
while($row = $all_cities->fetch_array()) { $myarray["ascii_name"] = $row["ascii_name"]; $returnarray[] = $myarray; } echo json_encode($returnarray);
now using volley
task load android app. in onresponse
method want obtain each of city names , load arraylist<string>
using for
loop. code now, won't work since s
jsonobject
not jsonarray
.
@override public void onresponse(string s) { try { jsonobject jsonobject = new jsonobject(s); (int = 0; < jsonobject.length(); i++) { jsonobject = jsonobject.getjsonobject(i); ....... more code isn't relevant }
instead of
jsonobject jsonobject = new jsonobject(s);
use
jsonarray jsonarray = new jsonarray(s);
also think using stringrequest in volley. switch jsonobjectrequest in volley.
Comments
Post a Comment