Json对象和Json字符串之间的转换

时间:2023-12-09 22:01:37
json字符串转json对象,调用parse方法:

var b='{"name":"2323","sex":"afasdf","age":"6262"}'//json字符串
var bToObject=JSON.parse(b);
console.log(bToObject.name);//2323
json对象转为json字符串:

var a={"name":"tom","sex":"男","age":"24"}//json对象
var aToString=JSON.stringify(a);
console.log(aToString);//{"name":"tom","sex":"男","age":"24"}