In my android app, I get a json value and iterate through them by doing this
if (response != null) {
try {
JSONObject object = new JSONObject(response);
Iterator enu = object.keys();
ArrayList<String> locationList = new ArrayList<String>();
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();
}
}
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...
How do I loop through the json object in the same order as when they were inserted?
Thanks.
EDIT:
PHP
$data = array();
for ($i = 0; $i < $num_records; $i++) {
array_push($data,
array("id{$i}" => mysql_result($recordset, $i, 'id')),
array("location{$i}" => mysql_result($recordset, $i, 'location')),
array("date{$i}" => mysql_result($recordset, $i, 'date added'))
);
}