title: JSON Object Not Found
body: <p>I have a JSON <code>ArrayList[222, 222, 333, 444, 555, 666, 777]</code></p>
  
  <p>I need to only store value <code>[333,444,555,666,777]</code> in my JSON ArrayList.</p>
  
  <p>I already try the below code, but i failed to get JSON Object for value 444.
  The error encountered are : <code>Exception: org.json.JSONException: JSONObject["4"] not found.</code></p>
  
  <pre><code>//list to delete data
   int lengthJSONMerged = JSONmergedJSONDataLog.length();
  int count= lengthJSONMerged - 5; //5 is the max number should be in the array
  
  for(int u= count+1; u &lt; lengthJSONMerged+1;u++) { 
              String str = Integer.toString(u);
              JSONArray arrSessionDouble=(JSONArray)JSONmergedJSONDataLog.get(str); 
  }
  </code></pre>
  
  <p>The original data is below. I need to keep the latest 5 record. </p>
  
  <pre><code> {"1":[{"sessionID":"222","loginTime":"2019-02-25 15:10:03"}],
   "2":[{"sessionID":"222","loginTime":"2019-02-25 15:10:05"}],
  "3":[{"sessionID":"333","loginTime":"2019-02-25 15:10:11"}],
   "4":[{"sessionID":"444","loginTime":"2019-02-25 15:10:17"}],
   "5":[{"sessionID":"555","loginTime":"2019-02-25 15:10:26"}],
   "6":[{"sessionID":"666","loginTime":"2019-02-25 15:10:35"}],
   "7":[{"sessionID":"777","loginTime":"2019-02-25 17:09:30"}]}
  </code></pre>
  
  <p>Do you have any idea why I'm getting that error.
  When i try to hard code and run my Java Program, i managed to get the value for attributes "4".</p>
  
  <p>Code that i used to hard code and get the vakue for attributes 4.</p>
  
  <pre><code>JSONArray arrSessionDouble=(JSONArray)JSONmergedJSONDataLog.get("4");
  </code></pre>