Zifei Tong
Zifei Tong

Reputation: 1727

Problem of serializing javascript object to JSON string

My question is sort of stupid that why

JSON.stringify({"annotation": [{"x":1, "y":2}, {"x":1, "y":2}]})

does not return

{"annotation": [{"x": 1, "y": 2}, {"x": 1, "y": 2}]}

but returns

{"annotation":"[{\"x\": 1, \"y\": 2}, {\"x\": 1, \"y\": 2}]"}

and how can I get the first output?

Upvotes: 0

Views: 544

Answers (1)

Daniel Earwicker
Daniel Earwicker

Reputation: 116664

Are you using Prototype? This question may be related:

JSON.stringify() array bizarreness with Prototype.js

Upvotes: 2

Related Questions