I am doing some tests with the CVS version of Rhino 1.7R3, and I am
running into an issue with the JSON native object.
The problem involves the object returned when parsing a dictionary, if
the keys happen to be (string representations of) numbers. More
specifically:
js> var o1 = {"a": 100}
js> var o2 = {"1": 100}
js> var s1 = JSON.stringify(o1)
js> var s2 = JSON.stringify(o2)
js> s1
{"a":100}
js> s2
{"1":100}
So far, so good.
js> var n1 = JSON.parse(s1)
js> var n2 = JSON.parse(s2)
js> n1["a"]
100
js> n2["1"]
js> typeof(n2["1"])
undefined
The value with key "1" on n2 is strangely undefined. The attribute is
there though:
js> for (var k in n2) print(k, typeof(k), n2[k])
1 string undefined
And the value is hidden there somewhere as well, because:
js> JSON.stringify(n1)
{"a":100}
js> JSON.stringify(n2)
{"1":100}
Summarized, the two following statements do not return the same thing:
js> JSON.parse(JSON.stringify({"a": 100}))["a"]
100
js> JSON.parse(JSON.stringify({"1": 100}))["1"]
js>
As a comparison, the same thing work as expected with Prototype 1.6.1
JSON routines:
js> Object.toJSON({"a": 100}).evalJSON()["a"]
100
js> Object.toJSON({"1": 100}).evalJSON()["1"]
100
Is this a known problem? Am I missing something?
Thank you, best regards, and Happy New Year!
-Christian
--
Christian Grigis
Senior Software Engineer
NEXThink S.A. -- http://www.nexthink.com/
I've filed a bug and submitted a patch for that.
https://bugzilla.mozilla.org/show_bug.cgi?id=537483
Cheers,
Raphael
On Jan 1, 3:56 am, Christian Grigis <christian.gri...@nexthink.com>
wrote:
--N
-Christian