Bug Tracker

Ticket #1107 (closed bug: invalid)

Opened 1 year ago

Last modified 1 year ago

Opera .getJSON returns reordered results

Reported by: pavelkunc Assigned to: anonymous
Type: bug Priority: major
Milestone: 1.1.3 Component: core
Version: 1.1.2 Keywords:
Cc: Needs: Review

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

Change History

Changed 1 year ago by john

  • status changed from new to closed
  • resolution set to invalid
  • version set to 1.1.2
  • component changed from ajax to core
  • milestone set to 1.1.3

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 1 year ago by pavelkunc

Thanks for explanation.

Note: See TracTickets for help on using tickets.