有效 JSON语法就是这样的:
{
"username": "admin",
"password": "123"
}
但是如果我想传输'用户'数组(给出示例)而不是单个'用户'呢?
根据规范,代码是否为有效JSON?
[{
"username": "admin",
"password": "123"
}, {
"username": "bbvb",
"password": "sdfsdf"
}, {
"username": "asd",
"password": "222"
}]
如果没有,使用JSON传输值数组的最佳方法是什么? (并且用'最好的方式',我的意思是语法上的)
答案 0 :(得分:11)
是的,您的示例是有效的JSON - 这正是您想要使用数组的方式。
答案 1 :(得分:5)
不太知名的页面json.org有一个显示语法的图表。理解起来非常简单,恕我直言。
答案 2 :(得分:2)
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对象示例
{
"id":"21",
"language": "Json",
"edition": "second",
}
Json数组示例
{
"book": [
{
"id":"21",
"language": "Json",
"edition": "second"
},
{
"id":"42",
"language": "Json",
"edition": "third"
}]
}
答案 3 :(得分:1)
你在那里写的内容已经正确了:)
[{ "username" : "admin", "password" : "123" }, { "username" : "bbvb", "password" : "sdfsdf" }, { "username" : "asd", "password" : "222" }]