1.json对象
var obj ={
color:'red',
//属性名可以 用引号包裹
//出现不合法的 属性名称,可用用' car-num ' 包裹
'num':10,
'price':'100',
size:{
width:200,
height:100,
},
num:[1,2,3,4,null,false,true,undefined,NaN,Infinity]
}
json 不能存储函数
2.将对象 转化为 json 字符串 (JSON.stringify())
函数会被过滤掉
undefined NaN Infinity 会转成 null
console.log(JSON.stringify(obj));
3.json字符串 转成 对象 (JSON.parse())
var json = '{"color":"red","car-num":10, "price":100}'
console.log(JSON.parse(json));