Reputation: 11
I have a JSONArray :
public JSNArray getItems() {
JSONArray listjson = new JSONArray();
JSONObject fnl_json = new JSONObject();
//adding few items to fnl_json
listjson.add(fnl_json);
return fnal_json;
}
I am calling getItems function, how can I iterate through fnl_json from the called function?
Upvotes: 1
Views: 7385
Reputation: 699
To iterate a JSONArray
you can do:
JSONObject jsonObject = new JSONObject("jsonString");
JSONArray jsonArray = jsonObject.getJSONArray("arrayName");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject explrObject = jsonArray.getJSONObject(i); // you will get the json object
//do the stuff
}
Upvotes: 3