I had this error org.json.JSONException: Index 5 out of range [0..5)
and I know what does it mean JSONArray Exception : Index 50 out of range (0..50),
my error in this code, I want to do the get last id of in json object how to do that ?
JSONObject maxj = peoples.getJSONObject(peoples.length());
More explenation this is the below code:
JSONObject jsonObj = new JSONObject(myJSON);
peoples = jsonObj.getJSONArray("result");
System.out.println(peoples.length());
JSONObject maxj = peoples.getJSONObject(peoples.length());//here is the error because
String j_id= maxj.getString("id");// and here
Listitem = new ArrayList<Listitem>();
for(int i=0;i<peoples.length();i++){
JSONObject c = peoples.getJSONObject(i);
// String id ="2";
String id= c.getString("id");
String url = c.getString("url");
in this code is entering a loop and getting the id ( 1,2,3,4)
String id= c.getString("id");
what I want only last value the max
which is 4
, so how to do that?