【问题标题】:Accessing Children in Json Array of Objects访问 Json 对象数组中的子项
【发布时间】:2018-04-30 02:45:48
【问题描述】:

创建了一个 Mock Json 服务器并能够通过 localhost:3000/JOBS 访问它。 如何访问 URL 中的子“包裹”,例如访问 localhost:3000/JOBS?type=open 之类的打开类型。提前致谢。

我有一个如下的 Json 对象数组:

{
  "JOBS": [
    {
      "Id": "1",
      "type": "open",
      "driver": "Andy",
      "receiver": "Paul",
      "price": "635.50",

      "Parcels": [
        {
          "parcelId": "90"
        }
      ]
    }
  ]
}

【问题讨论】:

    标签: json react-native children


    【解决方案1】:

    现在你不能按原样只访问Parcels

    你需要修改你的树形结构,才能访问Parcels

    {
        "JOBS": [
            {
                "Id": "1",
                "type": "open",
                "driver": "Andy",
                "receiver": "Paul",
                "price": "635.50"
            }
        ],
        "PARCELS": [
            {
                "parcelId": "90"
            }
        ]
    }
    

    并以localhost:3000/PARCELS 的身份访问它,如本link 中所述并描述here

    【讨论】:

    • 谢谢,但我需要 JOBS 中的 Parcels,这似乎是另一个新数组,而不是子数组
    • 您需要为Parcels 创建一个单独的数组,并通过其唯一ID 或Job ID 将它们链接到Job
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多