1.字符串转JSON对象
var studentStr ='{"name":"小明","age":"18","sex":"男"}';
//浏览器支持的转化方式 JSON.parse(studentStr)
console.log("浏览器支持的转化方式"+JSON.parse(studentStr));
//jquery方式转化或使用Jquery..parseJSON( studentStr ))
console.log("jquery插件格式转化"+$.parseJSON( studentStr ));
//js的转化方式
console.log("js的转化方式"+eval('('+studentStr+')'));2.
2.JOSN对象转字符串
使用JSON.stringify()方法进行转换
例如:
var student={
"name":"小明",
"id":"001",
"age":10,
"birthDay":"Jan 29, 2022 5:21:31 PM"
}
console.log(JSON.stringify(student));
结果: