亚洲成A人片在线观看网站_成年网站免费视频A在线双飞_日日日日做夜夜夜夜无码_久久夜色撩人精品国产小说

JSON 備忘清單

這是理解和編(bian)寫 JSON 格式配置文件的(de)快(kuai)速參考備忘(wang)單。

入門

介紹

是一種基于文本的輕量級開放標準,專為(wei)人類可(ke)讀的數據交換而設計。

  • JSON 代表 JavaScript 對象表示法
  • JSON 易于讀寫。
  • JSON 是與語言無關的數據交換格式
  • JSON 文件擴展名為 .json
  • JSON Internet 媒體類型為 application/json

示例

{
  "name": "Jason",
  "age": 39,
  "height": 1.92,
  "gender": "M",
  "salary": 70000,
  "married": true,
  "children": [
    {"name": "Tom", "age": 9, "gender":"M"},
    {"name": "Ava", "age": 7, "gender":"F"}
  ]
}

類型

類型描述
Number雙精度浮點
String字符系列
Boolean“true”或“false”
Array有序的值序列
Value字符串、數字、布爾值、空值等
Object鍵/值對的無序集合
nullNull 或 Empty

字符串

\"雙引號 Double quote
\\反斜杠 Backslash
\/正斜杠 Forward slash
\b退格 Backspace
\f換頁 Form feed
\n換行 Newline
\r回車 Carriage return
\t標簽 Tab
\u后跟四個十六進制數字

示例

{
  "url": "//jaywcjlove.github.io",
  "msg" : "Hi,\n\"Quick Reference\"",
  "intro": "Share quick reference and cheat sheet for developers."
}

無效字符串

{ "foo": 'bar' }

Have to be delimited by double quotes

數字

類型說明
Integer數字 1-9、0 和正數或負數
Fraction0.3、3.9 等分數
Exponent指數,如 e、e+、e-、E、E+、E

示例

{
  "positive" : 12,
  "negative" : -1,
  "fraction" : 10.25,
  "exponent" : 1.0E+2,
  "zero" : 0
}

無效的數字

{ "foo": 0xFF }

在JSON中,只能使用十進制文(wen)字

對象 Objects

{
  "color": "Purple",
  "id": "210",
  "composition": {
    "R": 70,
    "G": 39,
    "B": 89
  },
  "empty_object": {}
}

用逗號分隔的(de)多個(ge)鍵/值對(dui)

數組 Arrays

[1, 2, 3, 4, 5]

[ 開始并以 ] 結束

對象數組

{
  "children": [
    { "name": "Jimmy Smith", "age": 15 },
    { "name": "Sammy Sosa", "age": 12 }
  ]
}

數組對象

{
  "attributes": ["a1", "a2"],
  "methods": ["getter", "setter"],
  "empty_array": []
}

二維陣列

{
  "my_sequences": [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9, 0],
    [10, 11]
  ]
}

對象的對象

{
  "Mark McGwire": {
    "hr": 65,
    "avg": 0.278
  },
  "Sammy Sosa": {
    "hr": 63,
    "avg": 0.288
  }
}

嵌套

{
  "Jack": {
    "id": 1,
    "name": "Franc",
    "salary": 25000,
    "hobby": ["a", "b"],
    "location": {
        "country": "A", "city": "A-A"
    }
  }
}

在 JavaScript 中訪問 JSON

訪問對象

let myObject = {
  "name": "Jason",
  "last": "Doe",
  "age": 39,
  "gender": "M",
  "salary": 70000,
  "married": true
};

myObject.name"Jason"
myObject["name"]"Jason"
myObject.age39
myObject.otherundefined
myObject[0]undefined

訪問嵌套

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.age2
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].genderTypeError: Cannot read...

訪問陣列

let myArray = [
  "Jason",
  "Doe",
  39,
  "M",
  70000,
  true
];

myArray[1]"Doe"
myArray[5]true
myArray[6]undefined

另見

  • (json.org)
  • (jsoneditoronline.org)
  • (tableconvert.com)