JSON 语法:传输数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/431494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSON Syntax: Transmitting an array
提问by Andreas Grech
A validJSON Syntax is something of the kind:
一个有效的JSON语法是什么样的东西:
{
"username": "admin",
"password": "123"
}
But what if I want to transmit an array of 'users' (given the example), instead of a single 'user' ?
但是,如果我想传输一组“用户”(给出示例)而不是单个“用户”怎么办?
Is the code below Valid JSON, according to the specifications?
根据规范,下面的代码是有效的 JSON 吗?
[{
"username": "admin",
"password": "123"
}, {
"username": "bbvb",
"password": "sdfsdf"
}, {
"username": "asd",
"password": "222"
}]
And if not, what is the best way to transmit an array of values across with JSON? (And with 'best way', I mean syntactically)
如果不是,那么使用 JSON 传输一组值的最佳方法是什么?(“最好的方式”,我的意思是语法上)
采纳答案by Andrew Hare
Yes, your example is valid JSON - that is exactly how you want to use an array.
是的,您的示例是有效的 JSON - 这正是您想要使用数组的方式。
回答by Bombe
回答by Manish
Json Syntax Includes following.
Json 语法包括以下内容。
1. Data is represented in name/value pairs.
2. Each name is followed by ':'(colon).
3. The name/value pairs are separated by ,(comma).
4. Json object starts and ends with '{' and '}'.
5. Square brackets '[ ]' hold arrays and values are separated by
,(comma).
Json Objects Example
Json 对象示例
{
"id":"21",
"language": "Json",
"edition": "second",
}
Json Array Example
Json 数组示例
{
"book": [
{
"id":"21",
"language": "Json",
"edition": "second"
},
{
"id":"42",
"language": "Json",
"edition": "third"
}]
}
I have taken reference from http://www.tutsway.com/json-syntax.php
回答by sikachu
What you wrote up there is already correct :)
你在那里写的已经是正确的:)
[{ "username" : "admin", "password" : "123" }, { "username" : "bbvb", "password" : "sdfsdf" }, { "username" : "asd", "password" : "222" }]

