I am getting a string which I'm trying to convert to JSONArray. The length of the JSONArray is getting OK (if its 100 or 5000). but I am getting "java.lang.IndexOutOfBoundsException: Invalid index 50, size is 50". Below is my code.
try
{
JSONArray jsonArray = new JSONArray(returndResultForSNID);
System.out.println("jsonArray: "+jsonArray.length());
for(int i = 0; i < jsonArray.length(); i++)
{
snid = jsonArray.getJSONObject(i).getString("snid");
//number = jsonArray.getJSONObject(i).getString("phone");
phoneContactsDTOArrayList.add(new PhoneContactsDTO( contactNameArr.get(i).toString() , contactPhoneNumberArr.get(i).toString(), snid, "") );
//System.out.println( "Could jsonArray parse malformed JSON: " + snid +" _> "+number);
}
}
catch (Exception e)
{
System.out.println( "JSONArray error: " + e.toString() );
}