I'll elaborate a bit more on ChrisR awesome answer and bring images from his awesome reference.
一个有效的JSON总是以大括号{
或方括号[
开头,而不是别的.
{
will start an object
:{ "key": value, "another key": value }
Hint:虽然javascript接受单引号
'
,但JSON只接受双引号"
.
[
will start an array
:[value, value]
Hint: spaces among elements are always ignored by any JSON parser.
value
is an object
, array
, string
, number
, bool
or null
:So yeah, ["a", "b"]
is a perfectly valid JSON, like you could try on the link Manish pointed.
下面是几个额外的有效JSON示例,每个块一个:
{}
[0]
{"__comment": "json doesn't accept comments and you should not be commenting even in this way", "avoid!": "also, never add more than one key per line, like this"}
[{ "why":null} ]
{
"not true": [0, false],
"true": true,
"not null": [0, 1, false, true, {
"obj": null
}, "a string"]
}