Skip to main content

Bug Tracker

Side navigation

#1107 closed bug (invalid)

Opened April 06, 2007 04:13PM UTC

Closed April 06, 2007 05:49PM UTC

Last modified June 19, 2007 10:00AM UTC

Opera .getJSON returns reordered results

Reported by: pavelkunc Owned by:
Priority: major Milestone: 1.1.3
Component: core Version: 1.1.2
Keywords: Cc:
Blocked by: Blocking:
Description

You can check it live: http://pavel.fry-it.com/operabug/index.htm

Problem

I put simple JSON string in the /scale.js:

{"54":"a","56":"b","6":"c","5":"d"}

I parse this JSON string with getJSON jQuery (jQuery is from trunk) method and just append results to the results paragraph with this code:

$(document).ready(function() {

$.getJSON('scale.js', function(json){

for(var i in json) {

$('#results').append(i + ' -> ' + json[i] + "

");

}

});

});

If you run this with Firefox 2.0.0.3 (I have) you will see that values in results are in alphabetic order (and should be because that's order in JSON), but if your open this in Opera 9.10 you will see that the order is wrong, because results are ordered by key numericaly.

What's wrong?

Results (opera)

5 -> d

6 -> c

54 -> a

56 -> b

Results (Firefox)

54 -> a

56 -> b

6 -> c

5 -> d

Attachments (0)
Change History (2)

Changed April 06, 2007 05:49PM UTC by john comment:1

component: ajaxcore
milestone: → 1.1.3
resolution: → invalid
status: newclosed
version: → 1.1.2

That's correct. The ordering of properties within an object are not guaranteed (as you can see by the Opera results). There is no way to preserve, or enforce, a specific ordering within a browser (Unless you put all the properties in individual objects inside of an array.)

[{54: "a"}, {56: "b"}, {6: "c"}, {5, "d"}]

Changed April 07, 2007 11:13AM UTC by pavelkunc comment:2

Thanks for explanation.