• json使用类型总结


    一、json值:

    1、JSON 值可以是: 

    (1)数字(整数或浮点数)

    (2)字符串(在双引号中)

    (3)逻辑值(true false

    (4)数组(在中括号中)

    (5)对象(在大括号中)

    (6)null

    2、举例:

    (1)json数字:JSON 数字可以是整型或者浮点型:

    { "age":30 }

    (2)json对象:JSON 对象在大括号({})中书写,对象可以包含多个名称/值对:

    { "name":"菜鸟教程" , "url":"www.runoob.com" }

    (3)json数组:JSON 数组在中括号中书写,数组可包含多个对象:

    {
    "sites": [
    { "name":"菜鸟教程" , "url":"www.runoob.com" }, 
    { "name":"google" , "url":"www.google.com" }, 
    { "name":"微博" , "url":"www.weibo.com" }
    ]
    }

    (4)json布尔值:JSON 布尔值可以是 true 或者 false:

    { "flag":true }

    (5)json null:

    { "runoob":null }

    二、json使用javascript语法:

    var sites = [
        { "name":"runoob" , "url":"www.runoob.com" }, 
        { "name":"google" , "url":"www.google.com" }, 
        { "name":"微博" , "url":"www.weibo.com" }
    ];

    三、json对象:

    1、json对象语法:

    myObj = { "name":"runoob", "alexa":10000, "site":null };

    2、嵌套json对象:  

    myObj = {
        "name":"runoob",
        "alexa":10000,
        "sites": {
            "site1":"www.runoob.com",
            "site2":"m.runoob.com",
            "site3":"c.runoob.com"
        }
    }

    四、json数组:

    1、json数组语法:JSON 数组在中括号中书写

    [ "Google", "Runoob", "Taobao" ]

    2、json对象中的数组:

    {
    "name":"网站",
    "num":3,
    "sites":[ "Google", "Runoob", "Taobao" ]
    }

    3、嵌套json对象中的数组:JSON 对象中数组可以包含另外一个数组,或者另外一个 JSON 对象

    myObj = {
        "name":"网站",
        "num":3,
        "sites": [
            { "name":"Google", "info":[ "Android", "Google 搜索", "Google 翻译" ] },
            { "name":"Runoob", "info":[ "菜鸟教程", "菜鸟工具", "菜鸟微信" ] },
            { "name":"Taobao", "info":[ "淘宝", "网购" ] }
        ]
    }

    参考来源:菜鸟教程

  • 相关阅读:
    关于这个 blog
    P6499 [COCI2016-2017#2] Burza 题解
    CF1172F Nauuo and Bug 题解
    CF1479D Odd Mineral Resource 题解
    CF1442E Black, White and Grey Tree 题解
    CF1442D Sum 题解
    CF1025D Recovering BST 题解
    CF1056E Check Transcription 题解
    CF1025F Disjoint Triangles 题解
    红包算法的PHP实现
  • 原文地址:https://www.cnblogs.com/wangyuxue/p/11327599.html
Copyright © 2020-2023  润新知