什么是JSON
- JSON: JavaScript Object Notation(JavaScript 对象表示法)
- JSON 是轻量级的文本数据交换格式
- JSON 文件的文件类型是 .json
- JSON 文本的 MIME 类型是 application/json
普通的JS对象
{ name:"pangjian",
height:180,
site:null }
JSON格式的JS对象语法
{ "name":"pangjian",
"height":180,
"site":null }
JSON格式的字符串(本质是字符串)
"{ "name":"pangjian",
"height":180,
"site":null }"
对象可以包含多个 key/value(键/值)对。key 必须是字符串,value 可以是合法的 JSON 数据类型(字符串, 数字, 对象, 数组, 布尔值或 null)。
JSON对象中数组
{
"list":[ "Google", "Runoob", "Taobao" ]
}
JSON 数组在中括号中书写。
嵌套JSON对象中的数组
myObj = {
"sites": [
{ "name":"Google", "info":[ "Android", "Google 搜索", "Google 翻译" ] },
{ "name":"Runoob", "info":[ "菜鸟教程", "菜鸟工具", "菜鸟微信" ] },
{ "name":"Taobao", "info":[ "淘宝", "网购" ] }
]
}
最外层是myObj的JSON对象 ,里面有一个JSON数组sites,sites数组包含了三个JSON对象,每一个JSON对象里面还有一个JSON数组