javascript JSON.parse and JSON.stringify

var jstu = '{"name": "xiaoqiang", "age": 18}';
console.log(jstu);

var obj = JSON.parse(jstu);

console.log(obj.name);
console.log(obj.age);
console.log(typeof obj);

var obj2 = {"name": "xiaoqiang", "age": 12};
var obj2_string = JSON.stringify(obj2);
console.log(typeof obj2_string);

output:

{"name": "xiaoqiang", "age": 18}
xiaoqiang
18
object
string

 

posted @ 2019-06-03 16:21  嵌入式实操  阅读(108)  评论(0编辑  收藏  举报