javascript json语句 与 js语句的互转

 1 //var data = "weihexin"
 2 //var data = ["weihexin", 1]
 3 var data = {name:"weihexin", id:1}
 4 
 5 
 6 var json = JSON.stringify(data);//返回 json string
 7 console.log(json);//{"name":"weihexin","id":1}
 8 
 9 var _data = JSON.parse(json);//返回 js Object
10 console.log(_data);//{name: "weihexin", id: 1}

 

posted @ 2020-02-16 17:02  鸡儿er  阅读(147)  评论(0编辑  收藏  举报