Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#1107 closed bug (invalid)

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

Change History (2)

comment:1 Changed 13 years ago by john

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"}]

comment:2 Changed 13 years ago by pavelkunc

Thanks for explanation.

Note: See TracTickets for help on using tickets.