博客 / 詳情

返回

Y 分鐘速成 json

源代碼下載: learnjson-cn.json

因為 JSON 是一個極其簡單的數據交換格式,本教程最有可能成為有史以來最簡單的 Learn X in Y Minutes。

純正的 JSON 實際上沒有註釋,但是大多數解析器都接受 C- 風格(//, /* */)的註釋。為了兼容性,最好不要在其中寫這樣形式的註釋。

因此,本教程的一切都會是 100% 有效的 JSON 。幸虧,它的表達能力很豐富。

支持的數據類型:

  • 字符串: "hello", "\"A quote.\"", "\u0abe", "Newline.\n"
  • 數字: 23, 0.11, 12e10, 3.141e-10, 1.23e+4
  • 對象: { "key": "value" }
  • 數組: ["Values"]
  • 其他: true, false, null
{
  "numbers": 0,
  "strings": "Hellø, wørld. All unicode is allowed, along with \"escaping\".",
  "has bools?": true,
  "nothingness": null,

  "big number": 1.2e+100,

  "objects": {
    "comment": "Most of your structure will come from objects.",

    "array": [0, 1, 2, 3, "Arrays can have anything in them.", 5],

    "another object": {
      "comment": "These things can be nested, very useful."
    }
  },

  "silliness": [
    {
      "sources of potassium": ["bananas"]
    },
    [
      [1, 0, 0, 0],
      [0, 1, 0, 0],
      [0, 0, 1, "neo"],
      [0, 0, 0, 1]
    ]
  ],

  "that was short": "And, you're done. You now know everything JSON has to offer."
}

有建議?或者發現什麼錯誤?在 Github 上開一個 issue ,或者發起 pull request!


原文由 Anna Harren 編寫,並由 0 個好心人 修改。
Translated by:Zach Zhang
© 2022 Anna Harren
本作品採用 CC BY-SA 3.0 協議進行許可。

user avatar buxia97 頭像 ailim 頭像 79px 頭像 joytime 頭像 fehaha 頭像 codeoop 頭像 notrynosuccess 頭像
7 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.