JSON 语法:传输数组

发布于 2024-07-12 13:36:30 字数 438 浏览 7 评论 0原文

有效 JSON 语法是这样的:

{
  "username": "admin",
  "password": "123"
}

但是,如果我想传输一组“用户”(给出示例),而不是单个“用户”,该怎么办?

根据规范,下面的代码是有效的 JSON 吗?

[{
  "username": "admin",
  "password": "123"
}, {
  "username": "bbvb",
  "password": "sdfsdf"
}, {
  "username": "asd",
  "password": "222"
}]

如果没有,使用 JSON 传输值数组的最佳方法是什么? (“最佳方式”,我的意思是语法上)

A valid JSON Syntax is something of the kind:

{
  "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?

[{
  "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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

若沐 2024-07-19 13:36:30

是的,您的示例是有效的 JSON - 这正是您想要使用数组的方式。

编辑这里有一个关于 JSON 及其用法的很好的链接。

Yes, your example is valid JSON - that is exactly how you want to use an array.

Edit : Here is a good link on JSON and its usage.

没有伤那来痛 2024-07-19 13:36:30

不太知名的页面 json.org 有一个显示语法的图表。 恕我直言,这非常容易理解。

The not-very-well-known page json.org has a diagram that shows the syntax. It’s extremely simple to understand, IMHO.

神也荒唐 2024-07-19 13:36:30

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"
        }]
        }

我参考了 http://www.tutsway.com/json-syntax.php

Json Syntax Includes following.

 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

    {
    "id":"21",
    "language": "Json",
    "edition": "second",
    }

Json Array Example

  {
        "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

箜明 2024-07-19 13:36:30

你在那里写的已经是正确的:)

[{ "username" : "admin", "password" : "123" }, { "username" : "bbvb", "password" : "sdfsdf" }, { "username" : "asd", "password" : "222" }]

What you wrote up there is already correct :)

[{ "username" : "admin", "password" : "123" }, { "username" : "bbvb", "password" : "sdfsdf" }, { "username" : "asd", "password" : "222" }]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文