目录

json 基本语法介绍

一、前言

JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation)。
JSON 是轻量级的文本数据交换格式,目前大部分智能家居系统数据交换都使用了 Json 格式。

二、语法

JSON 数据的书写格式是:key : value,即: 键 : 键值,也就是:名称 : 数值

数组:"名称" : [ 组员 , 组员 , ……组员],
  • 组员:为 无名数组无名对象无名数值
  • 说明:“无名”表示没有名称的一个对象体/数组体/数值
对象:"名称" : { 成员 , 成员 , ……成员},
  • 成员:为 有名数组有名对象有名成员
成员:"名称" : "数值",
  • 数值:任意字符;如果 数值 没有双引号,只能数字、ture、false、null
要点:整个Json数据需要 { } 括号括住, } 或 ] 前面不能有逗号

三、例子

点击展开内容
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{
	"web-app":
	{
		"servlet": 
		[
			{
				"servlet-name": "cofaxCDS",
				"servlet-class": "org.cofax.cds.CDSServlet",
				"init-param":
				{
					"useDataStore": true,
					"useJSP": false,
					"xxx": null,
					"dataStoreMaxConns": 100,
					"maxUrlLength": 500,
					"dataStoreLogLevel": "debug",
					"configGlossary:adminEmail": "ksm@pobox.com",
					"configGlossary:poweredByIcon": "/images/cofax.gif",
					"configGlossary:staticPath": "/content/static",
					"jspListTemplate": "listTemplate.jsp",
					"searchEngineFileTemplate": "forSearchEngines.htm",
					"searchEngineRobotsDb": "WEB-INF/robots.db",
					"dataStoreClass": "org.cofax.SqlDataStore"
				}
			},
			{
				"servlet-name": "cofaxEmail",
				"servlet-class": "org.cofax.cds.EmailServlet",
				"init-param":
				{
					"mailHost": "mail1",
					"mailHostOverride": "mail2"
				}
			},
			{
				"servlet-name": "cofaxAdmin",
				"servlet-class": "org.cofax.cds.AdminServlet"
			},
			{
				"servlet-name": "fileServlet",
				"servlet-class": "org.cofax.cds.FileServlet"
			},
			{
				"servlet-name": "cofaxTools",
				"servlet-class": "org.cofax.cms.CofaxToolsServlet",
				"init-param":
				{
					"templatePath": "toolstemplates/",
					"log": 1,
					"logLocation": "/usr/local/tomcat/logs/CofaxTools.log",
					"logMaxSize": "",
					"dataLog": 1,
					"betaServer": true
				}
			}
		],
		"servlet-mapping":
		{
			"cofaxCDS": "/",
			"cofaxEmail": "/cofaxutil/aemail/*",
			"cofaxAdmin": "/admin/*",
			"fileServlet": "/static/*",
			"cofaxTools": "/tools/*"
		},
		"taglib":
		{
			"taglib-uri": "cofax.tld",
			"taglib-location": "/WEB-INF/tlds/cofax.tld"
		},
		"oil-price":
		{
			"status": "ok",
			"msg": "全国各省份汽柴油价格信息",
			"update": "2019-07-21 11:00",
			"data":
			[
				["地区", "92号汽油", "95号汽油", "98号汽油", "0号柴油"], 
				"直辖市:",
				["北京", "6.78", "7.21", "8.19", "6.45"], 
				["上海", "6.74", "7.17", "7.87", "6.39"], 
				["重庆", "6.75", "7.18", "8.06", "6.37"], 
				"省份:",
				["广东", "6.77", "7.15", "8.07", "6.41"]
			],
			"About": "xiaomin",
			"Blog": ["www.xxxxx1.com", "www.xxxxx2.com"]
		}
	}
}

四、工具

点击展开内容

JSONedit-格式化与语法检测工具下载
JSONEditorOnline-在线格式化与语法检测工具
菜鸟工具JSON在线解析-在线格式化与语法检测工具

五、资料

点击展开内容

官网Json中国