这就是有效JSON所需要的,对吧?
["somestring1", "somestring2"]
Run Code Online (Sandbox Code Playgroud)
cre*_*gox 283
我将详细介绍ChrisR非常棒的答案,并从他精彩的参考文献中提取图像.
有效的JSON始终以花括号{或方括号开头[,没有别的.
{将开始object:
{ "key": value, "another key": value }
Run Code Online (Sandbox Code Playgroud)
提示:虽然javascript接受单引号
',但JSON只接受双引号".
[将开始array:
[value, value]
Run Code Online (Sandbox Code Playgroud)
提示:任何JSON解析器都会忽略元素之间的空格.
value是object,array,string,number,bool或null:
所以,是的,["a", "b"]是一个完全有效的JSON,就像你可以尝试Manish指向的链接.
以下是一些额外有效的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"]
}
Run Code Online (Sandbox Code Playgroud)
小智 54
在这种情况下,您的JSON对象是一个列表.JSON几乎总是一个具有属性的对象; 一组一个或多个键:值对,因此您很可能会看到一个字典:
{ "MyStringArray" : ["somestring1", "somestring2"] }
Run Code Online (Sandbox Code Playgroud)
然后你可以要求价值,"MyStringArray"你会得到两个字符串的列表,"somestring1"和"somestring2".
我使用http://jsonlint.com/来验证我的JSON.
小智 6
String strJson="{\"Employee\":
[{\"id\":\"101\",\"name\":\"Pushkar\",\"salary\":\"5000\"},
{\"id\":\"102\",\"name\":\"Rahul\",\"salary\":\"4000\"},
{\"id\":\"103\",\"name\":\"tanveer\",\"salary\":\"56678\"}]}";
Run Code Online (Sandbox Code Playgroud)
这是一个带有Employeeas对象的JSON字符串的示例,然后是数组中的多个字符串和值作为对@cregox... 的引用
有点复杂,但可以在单个JSON字符串中解释很多.
| 归档时间: |
|
| 查看次数: |
334768 次 |
| 最近记录: |