什么是 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成为理想的数据交换语言。
JSON具有以下这些形式:
对象是一个无序的“‘名称/值’对”集合。一个对象以“{”(左括号)开始,“}”(右括号)结束。每个“名称”后跟一个“:”(冒号);“‘名称/值’ 对”之间使用“,”(逗号)分隔。
{
"key1":100,
"key2":20
}
{
"key1" : "张三",
"key2" : "大忽悠"
}
{
"key" : [000, 111111],
"key1" : [18874, 15157]
}
{
"key" : {"1": "亚索"},
"key1" : {"2": "刘备"}
}
{
"我" : [
{"key": "好好学习"},
{"key1": "天天向上"}
]
}
{
"我" : {
"你" : [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"
}