This is all you need for valid JSON, right?
这就是有效JSON所需要的,对吧?
["somestring1", "somestring2"]
4 个解决方案
#1
226
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.
一个有效的JSON总是以花括号{或方括号[,没有别的了。
{
will start an object
:
{ "key": value, "another key": value }
Hint: although javascript accepts single quotes
'
, JSON only takes double ones"
.提示:虽然javascript接受单引号,但JSON只接受双引号。
[
will start an array
:
[value, value]
Hint: spaces among elements are always ignored by any JSON parser.
提示:任何JSON解析器都会忽略元素之间的空格。
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.
是的,[a", "b"]是一个完全有效的JSON,就像你可以尝试链接Manish point一样。
Here are a few extra valid JSON examples, one per block:
这里有一些额外的有效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"]
}
#2
45
Your JSON object in this case is a list. JSON is almost always an object with attributes; a set of one or more key:value pairs, so you most likely see a dictionary:
这里的JSON对象是一个列表。JSON几乎总是具有属性的对象;一组或多个键:值对,所以您很可能会看到字典:
{ "MyStringArray" : ["somestring1", "somestring2"] }
then you can ask for the value of "MyStringArray"
and you would get back a list of two strings, "somestring1"
and "somestring2"
.
然后您可以询问“MyStringArray”的值,您将得到两个字符串的列表,“somestring1”和“somestring2”。
I use http://jsonlint.com/ to validate my JSON.
我使用http://jsonlint.com/验证我的JSON。
#3
38
Basically yes, JSON is just a javascript literal representation of your value so what you said is correct.
基本上,JSON只是你的值的javascript文字表示,所以你说的是对的。
You can find a pretty clear and good explanation of JSON notation on http://json.org/
您可以在http://json.org/上找到一个非常清楚、很好的JSON符号解释。
#4
4
String strJson="{\"Employee\":
[{\"id\":\"101\",\"name\":\"Pushkar\",\"salary\":\"5000\"},
{\"id\":\"102\",\"name\":\"Rahul\",\"salary\":\"4000\"},
{\"id\":\"103\",\"name\":\"tanveer\",\"salary\":\"56678\"}]}";
This is an example of a JSON string with Employee
as object, then multiple strings and values in an array as a reference to @cregox
...
这是一个JSON字符串的例子,Employee作为对象,然后是数组中的多个字符串和值作为对@cregox的引用……
A bit complicated but can explain a lot in a single JSON string.
有点复杂,但可以在一个JSON字符串中解释很多。
#1
226
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.
一个有效的JSON总是以花括号{或方括号[,没有别的了。
{
will start an object
:
{ "key": value, "another key": value }
Hint: although javascript accepts single quotes
'
, JSON only takes double ones"
.提示:虽然javascript接受单引号,但JSON只接受双引号。
[
will start an array
:
[value, value]
Hint: spaces among elements are always ignored by any JSON parser.
提示:任何JSON解析器都会忽略元素之间的空格。
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.
是的,[a", "b"]是一个完全有效的JSON,就像你可以尝试链接Manish point一样。
Here are a few extra valid JSON examples, one per block:
这里有一些额外的有效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"]
}
#2
45
Your JSON object in this case is a list. JSON is almost always an object with attributes; a set of one or more key:value pairs, so you most likely see a dictionary:
这里的JSON对象是一个列表。JSON几乎总是具有属性的对象;一组或多个键:值对,所以您很可能会看到字典:
{ "MyStringArray" : ["somestring1", "somestring2"] }
then you can ask for the value of "MyStringArray"
and you would get back a list of two strings, "somestring1"
and "somestring2"
.
然后您可以询问“MyStringArray”的值,您将得到两个字符串的列表,“somestring1”和“somestring2”。
I use http://jsonlint.com/ to validate my JSON.
我使用http://jsonlint.com/验证我的JSON。
#3
38
Basically yes, JSON is just a javascript literal representation of your value so what you said is correct.
基本上,JSON只是你的值的javascript文字表示,所以你说的是对的。
You can find a pretty clear and good explanation of JSON notation on http://json.org/
您可以在http://json.org/上找到一个非常清楚、很好的JSON符号解释。
#4
4
String strJson="{\"Employee\":
[{\"id\":\"101\",\"name\":\"Pushkar\",\"salary\":\"5000\"},
{\"id\":\"102\",\"name\":\"Rahul\",\"salary\":\"4000\"},
{\"id\":\"103\",\"name\":\"tanveer\",\"salary\":\"56678\"}]}";
This is an example of a JSON string with Employee
as object, then multiple strings and values in an array as a reference to @cregox
...
这是一个JSON字符串的例子,Employee作为对象,然后是数组中的多个字符串和值作为对@cregox的引用……
A bit complicated but can explain a lot in a single JSON string.
有点复杂,但可以在一个JSON字符串中解释很多。