Reputation: 3761
I'm using JSON
in my android application in the following manner:
Code:
Integer numberOfItemsInResp = pagination.getInt("items");
JSONArray results = jsonResponse.getJSONArray("results");
for (int i = 0; i < numberOfItemsInResp; i++){
JSONObject perResult = results.getJSONObject(i);
}
Problem is when the i reaches 50, then JSONObject perResult = results.getJSONObject(i)
throws "org.json.JSONException: Index 50 out of range [0..50)" Exception.
Is there any limitation attached to JSONArray?
Upvotes: 3
Views: 9631
Reputation: 496
Just do a simple debug, see how your array looks like, most likely you don't have enough items in the array as the index you provide, the answers above are pretty clear in this regard.
Upvotes: 0
Reputation: 54801
What is numberOfItemsInResp
? Suggest you do this:
JSONArray results = jsonResponse.getJSONArray("results");
final int numberOfItemsInResp = results.length();
for (int i = 0; i < numberOfItemsInResp; i++){
JSONObject perResult = results.getJSONObject(i);
}
Upvotes: 8