【问题标题】:List Objects in JSON以 JSON 格式列出对象
【发布时间】:2016-05-13 21:42:27
【问题描述】:

对于 List of Objects ,哪一种是正确的 JSON 语法? 我在不同的来源看到了不同的实现。

{
  "Employees": [
        {
          "name": "foo",
          "age": 23
        },
        {
          "name": "bar",
          "age": 37
        }
      ]
}

{
  "employees": [
        {
          "employee": {
            "name": "foo",
            "age": 23
          }
        },
        {
          "employee": {
            "name": "bar",
            "age": 37
          }
        }
      ]
}

【问题讨论】:

  • 我认为第一个更标准,但这只是约定俗成的问题;它们在技术上都是有效的。

标签: arrays json list object


【解决方案1】:

对于您的数据类型,我更喜欢第一个。

{
  "Employees": [
        {
          "name": "foo",
          "age": 23
        },
        {
          "name": "bar",
          "age": 37
        }
      ]
}

假设您要检索员工。

var firstEmployee = Employees[0]

看起来合乎逻辑。

【讨论】:

    猜你喜欢
    • 2019-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-20
    • 1970-01-01
    • 2016-01-09
    • 2013-08-10
    相关资源
    最近更新 更多