这是理解和编写 JSON 格式配置文件的快速参考备忘单。
JSON 是一种基于文本的轻量级开放标准,专为人类可读的数据交换而设计。
.jsonapplication/json\" | 双引号 Double quote |
\\ | 反斜杠 Backslash |
\/ | 正斜杠 Forward slash |
\b | 退格 Backspace |
\f | 换页 Form feed |
\n | 换行 Newline |
\r | 回车 Carriage return |
\t | 标签 Tab |
\u | 后跟四个十六进制数字 |
{
"url": "https://jaywcjlove.github.io",
"msg" : "Hi,\n\"Quick Reference\"",
"intro": "为开发人员分享快速参考和备忘单"
}
{ "foo": 'bar' }
Have to be delimited by double quotes
对象键可以是 ECMAScript 5.1 IdentifierName
{
width: 1920,
height: 1080,
}
数组可以有一个尾随逗号
[
1,
true,
'three',
]
let myObject = {
"ref": {
"name": 0,
"last": 1,
"age": 2,
"gender": 3,
"salary": 4,
"married": 5
},
"jdoe": [
"Jason",
"Doe",
39,
"M",
70000,
true
],
"jsmith": [
"Tom",
"Smith",
42,
"F",
80000,
true
]
};
myObject.ref.age | 2 |
myObject["ref"]["age"] | 2 |
myObject.jdoe | ["Jason", "Doe", 39 ...] |
myObject.jsmith[3] | "F" |
myObject[1] | undefined |
let myArray = [
{
"name": "Jason",
"last": "Doe",
"age": 39,
"gender": "M",
"salary": 70000,
"married": true
},
{
"name": "Tom",
"last": "Smith",
"age": 42,
"gender": "F",
"salary": 80000,
"married": true
},
{
"name": "Amy",
"last": "Burnquist",
"age": 29,
"gender": "F",
"salary": 60000,
"married": false
}
];
myArray[0] | {"name": "Jason", ...} |
myArray[1].name | "Tom" |
myArray[1][2] | 42 |
myArray[3] | undefined |
myArray[3].gender | TypeError: Cannot read... |