json它是一种数据格式,不是一种编程语言,不是只有js才有json。
json校验网址:www.bejson.com
必须具备以下特点:
1、key添加双引号
2、末尾没有分号
3、同一对象中不允许出现两个同名属性
{ "name":"zb", "hobby":["sing","dance"], "work":{ "job":"前端开发", "address":"wuhan" } "member":[{ "name":"lili", "hobby":["sing","dance"] },{ "name":"ben", "hobby":["sing","dance"] } ] }
console.log(aa.hobby[1]);//dance
console.log(aa.work.job);//前端开发
console.log(aa.member[0].hobby[0]);//sing
序列化
JSON.stringify() //json对象转json字符串
JSON.parse() //json字符串转成json对象
var aa={ "name":"zb", "hobby":["sing","dance"], "work":{ "job":"前端开发", "address":"wuhan" } "member":[{ "name":"lili", "hobby":["sing","dance"] },{ "name":"ben", "hobby":["sing","dance"] } ] }
把json赋值给了aa
var test = JSON.stringify(aa,['name','member','work']);
console.log(test);//{"name":"zb","member":[{"name":"lili"},{"name":"ben"}],"work":{}}