JSON is sorted by key automatically in Firefox, Chrome and Opera
Notice: This thread is very old.
- radas
- Member | 225
Hi,
I have model method with this SQL (dibi):
->select(array('id', 'name'))
->from('table')
->orderBy('name', \dibi::ASC)
->fetchPairs()
Presenter:
public function handleLoad() {
if ($this->isAjax() {
$data = ... // call model method
$this->payload->data = $data; // array()
$this->sendPayload();
}
...
}
Firefox (25), Chrome (31) and Opera (12) sort JSON object by key:
Object {
3 = "Z...",
4 = "S...",
5 = "V..."
}
Internet Explorer 8 is ok.
Is possible, that Nette would it correct?
--
Nette 2.1-dev (2013–11–18)
Last edited by radas (2013-11-21 14:19)
- Jan Tvrdík
- Nette guru | 2595
@radas: JSON RFC: “An object is an unordered collection”. This is also true for javascript. Relying on the order of items in object is wrong.