//JSON.parse将字符串格式json转化为json对象 var str=‘{"name":"lingling","age":"26"}‘; console.log(JSON.parse(str));//输出:object{name:"lingling",age:"26"}//注意:str每个属性名都必须是双引号,不然会报错; //JSON.stringify()将一个json对象转化成字符串格式var a={a:1,b:2}; var b=JSON.stringify(a); console.log(JSON.stringify(a));//输出:{"a":"1","b":"2"} console.log(typeof(b));//输出:string
时间: 2024-10-05 11:44:45