源代码下载: 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 协定进行许可。