Json字符串和Json对象相互转换

字符串-->json对象:JSON.parse() 
var str = '{"code":"A001","name":"张三"}';
JSON.parse(str);
结果: 
code: "A001"
name: "张三"

 

json对象-->字符串:JSON.stringify()
var obj = {code:"A001",name:"张三"};
JSON.stringify(obj);
结果: 
"{"code":"A001","name":"张三"}"

 



 
posted @ 2018-12-19 14:42  杜子烟  阅读(175)  评论(0编辑  收藏  举报