Jquery getJSON sorts my data by id automatically
This is an associative array: order does not matter. The following JSON objects are equivalent:
{ "3" : "Danie Beach", "1" : "Miami", "2" : "Weston"}{ "1" : "Miami", "2" : "Weston", "3" : "Danie Beach"}
If you need an ordering, you should instead embed an array within the JSON:
{ "beaches" : [ {"key" : "3", "value" : "Danie Beach"}, {"key" : "1", "value" : "Miami"}, {"key" : "2", "value" : "Weston"} ]}
Example Usage:
jQuery.ajax({ ... dataType: 'json', success: function(data) { jQuery.each(data.beaches, function(i, beach) { alert(i+': beach['+beach.key+'] = '+beach.value); }); }});