JSONArray Exception : Index 50 out of range [0..50). Is there any limit on JsonArray

android, java, json

Solution

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);
}

Problem

I'm using `JSON` in my android application in the following manner: - Send request to a URL & receive JSON response. - Parse JSON response & fetch the required element "results" which is a JSON array. - Loop on every i'th element of this JSON array and continue with the required operation 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?

Original source