JavaScript Json 和 字符串 互转
JavaScript Json 和 字符串 相互转换
Json 转字符串
var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');
console.log( obj );
console.log("name:" + obj.name );
字符串 转 Json
var obj = {name: "John", age: 30, city: "New York"};
console.log( obj );
var jsonStr = JSON.stringify(obj);
console.log( jsonStr );
参考:
blog comments powered by Disqus