您如何表示一个JSON字符串数组? [英] How do you represent a JSON array of strings?
问题描述
这就是有效JSON所需的全部,对吧?
["somestring1", "somestring2"]
我将在 ChrisR 很棒的答案,并从他的很棒的推荐书中提取图像.
有效的JSON总是以花括号{
或方括号[
开头.
{
将启动object
:
{ "key": value, "another key": value }
提示:尽管javascript接受单引号
'
,但JSON只接受双引号"
.
[
将启动array
:
> /p>
[value, value]
提示:任何JSON解析器始终会忽略元素之间的空格.
value
是object
,array
,string
,number
,bool
或null
:
是的,["a", "b"]
是一个完全有效的JSON,就像您可以尝试Manish指向的链接. /p>
这里有一些额外的有效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"]
}
This is all you need for valid JSON, right?
["somestring1", "somestring2"]
I'll elaborate a bit more on ChrisR awesome answer and bring images from his awesome reference.
A valid JSON always starts with either curly braces {
or square brackets [
, nothing else.
{
will start an object
:
{ "key": value, "another key": value }
Hint: although javascript accepts single quotes
'
, JSON only takes double ones"
.
[
will start an array
:
[value, value]
Hint: spaces among elements are always ignored by any JSON parser.
And 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.
Here are a few extra valid JSON examples, one per block:
{}
[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"]
}
这篇关于您如何表示一个JSON字符串数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!