开发者

Javascript array serialized in JSON enclosed in quotes, like a string

In my web application, why do JSON.stringify serialize my Activity's Trackpoints array as a string? Notice in the JSON representation on top that the trackpoints array is enclosed in quotes, rendering it as a string. The javascript object representation in the bottom shows clearly that trackpoints 开发者_JAVA技巧is an array.

When this serialized activity is passed as JSON in a POST to my Sinatra back-end, Ruby parses its trackpoints as a string instead of an array of Trackpoint objects. The end result is a 500 server error, which is not what I expect.

Precision for people unable to see the included image: "The trackpoints array is a property of a complex object. JSON.stringify encloses it in quotes while doing its job. When Ruby parses the whole serialized object, it interprets my array as a string instead of an array. That's why I want to avoid those quotes."

Javascript array serialized in JSON enclosed in quotes, like a string

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜