JSON是什么
JSON ( JavaScript Object Notation) ,是一种数据交互格式。
Why
Json之前,大家都用 XML 传递数据。XML 是一种纯文本格式,所以适合在网络上交换数据,但是 XML 格式比较复杂,终于道格拉斯·克罗克福特(Douglas Crockford)发明了JSON 这种超轻量级的数据交换格式。
数据格式
JSON 实际上是 JavaScript 的一个子集,所以JSON 的数据格式和 JavaScript 是对应的:
- number => JS number
- boolean => JS boolean
- string => JS string //
- null => JS null
- array => JS Array 的表达方式 []
- object => JS {} 表达式
标准的JSON的合法符号:
{ (左大括号)
}(右大括号)
"" (双引号)
:(冒号)
, (逗号)
[ (左中括号)
] (右中括号)
JSON字符串:特殊字符可在字符前面加\或使用\u加四位16进制数来处理
{"name":"jobs"}
JSON布尔:必须小写的true和false
{"bool":true}
JSON空:必须小写的null
{"object":null}
JSON数值:不能使用8/16进制,需要十进制
{"num":60}
{"num":-60}
{"num",6.6666}
{"num",1e+6}<!-- 1乘10的6次方,e不区分大小写 -->
{"num",1e-6}<!-- 1乘10的负6次方,e不区分大小写 -->
JSON对象
{
"device":{
"NAME":"Bilizzard",
"price":60
}
}
JSON数组:
{
"person":[
"jobs",
60
]
}
JSON对象数组:
{
"array": [
{
"name": "jobs"
},
{
"name": "bill",
"age": 60
},
{
"product": "war3",
"type": "game",
"popular": true,
"price": 60
}
]
}
反例:
{"id" : ox16 } //不合法,数值需要是十进制
{"name" : underfined } //不合法,没有该值
[{
"name" : NUll,
"school" : function() {
console.log("该写法是错误的")
}//不合法
}]//json中不能使用自定义函数,或系统内置函数
注意事项
- JSON 规定字符集是UTF-8,字符串必须使用
""
,Object 的键也必须使用""
- 数组或对象的最后一个成员,不能加 逗号
综合示例:
{
"Devices": [{
"ID": 0,
"SerialNumber": "DS-7108N-F1/8P0820171010CCRR108669415WCVU",
"ChannelNumber": 8,
"StartChannel": 1,
"AlarmInNum": 0,
"AlarmOutNum": 0,
"IPChanNum": 8,
"MirrorChanNum": 0,
"StartMirrorChanNo": 0,
"LocalNodeName": "dev241",
"DeviceType": 2210,
"DiskNum": 1,
"LoginUserName": "zhaojingchen",
"LoginUserPwd": "zhaojingchen123",
"DeviceIP": "192.168.2.241",
"DeviceMultiIP": "0.0.0.0",
"DevicePort": 8000,
"DeviceName": "",
"LoginMode": 0,
"Https": 0,
"Channels": [{
"ChanID": 0,
"DeviceIndex": 0,
"ChanIndex": 0,
"ChanName": "IPCamera1",
"Protocol": 0,
"PicResolution": 0,
"PicQuality": 0,
"Enable": 1,
"PreviewMode": 0,
"PreviewProtocolType": 0,
"VideoCodingType": 0,
"StreamType": 0,
"LinkMode": 0
}, {
"ChanID": 1,
"DeviceIndex": 0,
"ChanIndex": 1,
"ChanName": "IPCamera2",
"Protocol": 0,
"PicResolution": 0,
"PicQuality": 0,
"Enable": 1,
"PreviewMode": 0,
"PreviewProtocolType": 0,
"VideoCodingType": 0,
"StreamType": 0,
"LinkMode": 0
}, {
"ChanID": 2,
"DeviceIndex": 0,
"ChanIndex": 2,
"ChanName": "IPCamera3",
"Protocol": 0,
"PicResolution": 0,
"PicQuality": 0,
"Enable": 1,
"PreviewMode": 0,
"PreviewProtocolType": 0,
"VideoCodingType": 0,
"StreamType": 0,
"LinkMode": 0
}, {
"ChanID": 3,
"DeviceIndex": 0,
"ChanIndex": 3,
"ChanName": "IPCamera4",
"Protocol": 0,
"PicResolution": 0,
"PicQuality": 0,
"Enable": 0,
"PreviewMode": 0,
"PreviewProtocolType": 0,
"VideoCodingType": 0,
"StreamType": 0,
"LinkMode": 0
}, {
"ChanID": 4,
"DeviceIndex": 0,
"ChanIndex": 4,
"ChanName": "IPCamera5",
"Protocol": 0,
"PicResolution": 0,
"PicQuality": 0,
"Enable": 0,
"PreviewMode": 0,
"PreviewProtocolType": 0,
"VideoCodingType": 0,
"StreamType": 0,
"LinkMode": 0
}, {
"ChanID": 5,
"DeviceIndex": 0,
"ChanIndex": 5,
"ChanName": "IPCamera6",
"Protocol": 0,
"PicResolution": 0,
"PicQuality": 0,
"Enable": 0,
"PreviewMode": 0,
"PreviewProtocolType": 0,
"VideoCodingType": 0,
"StreamType": 0,
"LinkMode": 0
}, {
"ChanID": 6,
"DeviceIndex": 0,
"ChanIndex": 6,
"ChanName": "IPCamera7",
"Protocol": 0,
"PicResolution": 0,
"PicQuality": 0,
"Enable": 0,
"PreviewMode": 0,
"PreviewProtocolType": 0,
"VideoCodingType": 0,
"StreamType": 0,
"LinkMode": 0
}, {
"ChanID": 7,
"DeviceIndex": 0,
"ChanIndex": 7,
"ChanName": "IPCamera8",
"Protocol": 0,
"PicResolution": 0,
"PicQuality": 0,
"Enable": 0,
"PreviewMode": 0,
"PreviewProtocolType": 0,
"VideoCodingType": 0,
"StreamType": 0,
"LinkMode": 0
}]
}]
}
2.
{
"CycleTime": 20,
"CyclePlay": 0,
"UseCard": 0,
"NTSC": 0,
"RecordFileInterval": 60,
"AutoRecord": 0,
"CycleRecord": 0,
"StartRecordDriver": 0,
"EndRecordDriver": 0,
"DownLoadPath": "D:\\DownLoad",
"PictureSavePath": "D:\\Picture",
"RemoteCfgSavePath": "D:\\SaveRemoteCfgFile",
"AutoCheckDeviceTime": 0,
"CheckDeviceTime": 0,
"AlarmDelayTime": 10,
"AlarmListenPort": 7200,
"AutoSaveLog": 1,
"AlarmInfo": 1,
"SuccLog": 1,
"FailLog": 1,
"NoDecode": 0,
"PreviewBlock": 1,
"OutputDebugString": 0,
"RecordTimes": [{
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}, {
"StartTime": 0,
"StopTime": 0
}],
"BFrameNum": 0,
"InSide": 1,
"LogLevel": 3,
"StandardCB": 0,
"Timeout": 5000
}