Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an Array var cars = [2,3,..] which holds a few integers.

(我有一个数组var cars = [2,3,..] ,其中包含一些整数。)

I've added a few values to the array, but I now need to send this array to a page via jQuery's .get method.

(我已经向数组添加了一些值,但是现在我需要通过jQuery的.get方法将此数组发送到页面。)

How can I convert it to a JSON object for sending?

(如何将其转换为JSON对象进行发送?)

  ask by dotty translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
161 views
Welcome To Ask or Share your Answers For Others

1 Answer

Script for backward-compatibility: https://github.com/douglascrockford/JSON-js/blob/master/json2.js

(向后兼容的脚本: https : //github.com/douglascrockford/JSON-js/blob/master/json2.js)

And call:

(并致电:)

var myJsonString = JSON.stringify(yourArray);

Note: The JSON object is now part of most modern web browsers (IE 8 & above).

(注意: JSON对象现在是大多数现代Web浏览器(IE 8及更高版本)的一部分。)

See caniuse for full listing.

(有关完整列表,请参见caniuse)

Credit goes to: @Spudley for his comment below

(感谢:@Spudley在下面的评论)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...