json的几种标准格式

目录

  • 1、简介
  • 2、JSON的标准格式
    • 2.1 JSON数值
    • 2.2 JSON字符串
    • 2.3 JSON数组
    • 2.4 JSON对象
    • 2.5 JSON对象数组
    • 2.6 JSON数组对象

1、简介

什么是 JSON ?

  • JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation)
  • JSON 是轻量级的文本数据交换格式
  • JSON 独立于语言
  • JSON 具有自我描述性,更易理解
  • JSON 使用 JavaScript 语法来描述数据对象,但是 JSON 仍然独立于语言和平台。JSON 解析器和 JSON 库支持许多不同的编程语言。

w3c的标准说明如下:
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。 易于人阅读和编写。同时也易于机器解析和生成。 它基于JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999的一个子集。 JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族的习惯(包括C, C++, C#, Java, JavaScript, Perl, Python等)。 这些特性使JSON成为理想的数据交换语言。

2、JSON的标准格式

JSON具有以下这些形式:
对象是一个无序的“‘名称/值’对”集合。一个对象以“{”(左括号)开始,“}”(右括号)结束。每个“名称”后跟一个“:”(冒号);“‘名称/值’ 对”之间使用“,”(逗号)分隔。

2.1 JSON数值

  • 格式:{ “key” : value}
  • 示例: {“key1”:100,“key2”:20}
{
    "key1":100,
    "key2":20
}

2.2 JSON字符串

  • 格式:{ “key” : “value”}
  • 示例: {“key1” : “张三”,“key2” : “大忽悠”}
  {
        "key1" : "张三",
        "key2" : "大忽悠"
    }

2.3 JSON数组

  • 格式:{ “key” : [value]}
  • 示例:{key" : [000, 111111],“key1” : [18874, 15157]}
 {
        "key" : [000, 111111],
        "key1" : [18874, 15157]
    }

2.4 JSON对象

  • 格式:{ “key” : {value}}
  • 示例: {“key” : {“1”: “亚索”},“key1” : {“2”: “刘备”}}
  {
        "key" : {"1": "亚索"},
        "key1" : {"2": "刘备"}
    }

2.5 JSON对象数组

  • 格式:{ “key” : [{“key1”: “value1”},{“key2”: “value2”}]}
  • 示例:{“我”:[{“key”: “好好学习”},{“key1”:“天天向上”}]}
  {
        "我" : [
                      {"key": "好好学习"},
                      {"key1": "天天向上"}
        ]
    }

2.6 JSON数组对象

  • 格式:{“key”:{“key1”:[value1,value2]}}
  • 示例:{“我”:{“你” : [18874,15157]}}
  {
        "我" : {
                      "你" : [18874,15157]           
        }
    }

综合运用示例:

{"cm":{"ln":"-55.0","sv":"V2.9.6","os":"8.0.4","g":"[email protected]","mid":"489","nw":"3G","l":"es","vc":"4","hw":"640*960","ar":"MX","uid":"489","t":"1593123253541","la":"5.2","md":"sumsung-18","vn":"1.3.4","ba":"Sumsung","sr":"I"},"ap":"app","et":[{"ett":"1593050051366","en":"loading","kv":{"extend2":"","loading_time":"14","action":"3","extend1":"","type":"2","type1":"201","loading_way":"1"}},{"ett":"1593108791764","en":"ad","kv":{"activityId":"1","displayMills":"78522","entry":"1","action":"1","contentType":"0"}},{"ett":"1593111271266","en":"notification","kv":{"ap_time":"1593097087883","action":"1","type":"1","content":""}},{"ett":"1593066033562","en":"active_background","kv":{"active_source":"3"}},{"ett":"1593135644347","en":"comment","kv":{"p_comment_id":1,"addtime":"1593097573725","praise_count":973,"other_id":5,"comment_id":9,"reply_count":40,"userid":7,"content":"辑赤蹲慰鸽抿肘捎"}}],"id":"1593136280858"}

看着不方便,用解析器解析一下:

{
    "cm":{
        "ln":"-55.0",
        "sv":"V2.9.6",
        "os":"8.0.4",
        "g":"[email protected]",
        "mid":"489",
        "nw":"3G",
        "l":"es",
        "vc":"4",
        "hw":"640*960",
        "ar":"MX",
        "uid":"489",
        "t":"1593123253541",
        "la":"5.2",
        "md":"sumsung-18",
        "vn":"1.3.4",
        "ba":"Sumsung",
        "sr":"I"
    },
    "ap":"app",
    "et":[
        {
            "ett":"1593050051366",
            "en":"loading",
            "kv":{
                "extend2":"",
                "loading_time":"14",
                "action":"3",
                "extend1":"",
                "type":"2",
                "type1":"201",
                "loading_way":"1"
            }
        },
        {
            "ett":"1593108791764",
            "en":"ad",
            "kv":{
                "activityId":"1",
                "displayMills":"78522",
                "entry":"1",
                "action":"1",
                "contentType":"0"
            }
        },
        {
            "ett":"1593111271266",
            "en":"notification",
            "kv":{
                "ap_time":"1593097087883",
                "action":"1",
                "type":"1",
                "content":""
            }
        },
        {
            "ett":"1593066033562",
            "en":"active_background",
            "kv":{
                "active_source":"3"
            }
        },
        {
            "ett":"1593135644347",
            "en":"comment",
            "kv":{
                "p_comment_id":1,
                "addtime":"1593097573725",
                "praise_count":973,
                "other_id":5,
                "comment_id":9,
                "reply_count":40,
                "userid":7,
                "content":"辑赤蹲慰鸽抿肘捎"
            }
        }
    ],
    "id":"1593136280858"
}

你可能感兴趣的:(json的几种标准格式)