title: How to iterate through all the json values in order as when they were inserted?
body: <p>In my android app, I get a json value and iterate through them by doing this</p>
  
  <pre><code>    if (response != null) {
          try {
              JSONObject object = new JSONObject(response);
              Iterator enu = object.keys();
              ArrayList&lt;String&gt; locationList = new ArrayList&lt;String&gt;();
              while(enu.hasNext()) {
                  locationList.add(object.getString((String) enu.next()));
              }
              callerContext.DisplayLocations(locationList);
          } catch (JSONException e) {
              Toast.makeText(callerContext, callerContext.getResources().getString(R.string.error_message), Toast.LENGTH_LONG).show();
          }
      }
  </code></pre>
  
  <p>The problem is the ArrayList if I then iterate through that, the values are in a different order then when I insert then in the php code...</p>
  
  <p>How do I loop through the json object in the same order as when they were inserted?</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>PHP</p>
  
  <pre><code>            $data = array();
              for ($i = 0; $i &lt; $num_records; $i++) {
  
                  array_push($data, 
                      array("id{$i}" =&gt; mysql_result($recordset, $i, 'id')), 
                      array("location{$i}" =&gt; mysql_result($recordset, $i, 'location')), 
                      array("date{$i}" =&gt; mysql_result($recordset, $i, 'date added'))
                  );
              }
  </code></pre>