JSON

作者: 我爱吃青苹果 | 来源:发表于2017-05-09 23:17 被阅读0次

JSON 对象

  • 语法
1.JSON 对象使用在大括号{}中书写
2.对象可以包含多个 key/value(键/值)对
3.key 必须是字符串,value 可以是合法的 JSON 数据类型(字符串, 数字, 对象, 数组, 布尔值或 null)
4.key 和 value 中使用冒号(:)分割
5.每个 key/value 对使用逗号(,)分割。
  • json对象可以看成是java中的Map集合,里面装着一系列的键值对
var myObj, x;
myObj = { "name":"runoob", "alexa":10000, "site":null };
x = myObj.name;
  • json对象中可以包含另外一个 json对象
myObj = {
    "name":"runoob",
    "alexa":10000,
    "sites": {
        "site1":"www.runoob.com",
        "site2":"m.runoob.com",
        "site3":"c.runoob.com"
    }
}

JSON 数组

  • 语法
1.JSON 数组在中括号中书写
2.JSON 中数组值必须是合法的 JSON 数据类型(字符串, 数字, 对象, 数组, 布尔值或 null)
  • 对象属性的值可以是一个数组
{
"name":"网站",
"num":3,
"sites":[ "Google", "Runoob", "Taobao" ]
}
  • JSON 对象中数组可以包含另外一个数组,或者另外一个 JSON 对象
myObj = {
    "name":"网站",
    "num":3,
    "sites": [
        { "name":"Google", "info":[ "Android", "Google 搜索", "Google 翻译" ] },
        { "name":"Runoob", "info":[ "教程", "工具", "微信" ] },
        { "name":"Taobao", "info":[ "淘宝", "网购" ] }
    ]
}

相关文章

网友评论

      本文标题:JSON

      本文链接:https://www.haomeiwen.com/subject/jbaitxtx.html