快捷搜索:  汽车  科技

js对象转换为json字符串(如何把一个js对象转化为json字符串)

js对象转换为json字符串(如何把一个js对象转化为json字符串)All current browsers have native JSON support built in. So as long as you're not dealing with prehistoric browsers like IE6/7 you can do it just as easily as that:var j={"name":"binchen"}; JSON.stringify(j); // '{"name":"binchen"}'说白了:JSON.stringify()。

今天在Stack Overflow上看到一个帖子,如何把js对象转化为json字符串。

If I defined an object in JS with:

var j={"name":"binchen"};

How can I convert the object to JSON? The output string should be:

'{"name":"binchen"}'

我们排除IE6、7,可以用下面这个小方法来达到转换的目的。

All current browsers have native JSON support built in. So as long as you're not dealing with prehistoric browsers like IE6/7 you can do it just as easily as that:

var j={"name":"binchen"}; JSON.stringify(j); // '{"name":"binchen"}'

js对象转换为json字符串(如何把一个js对象转化为json字符串)(1)

说白了:JSON.stringify()。

猜您喜欢: