在Json对象数组中访问子节点

时间:2018-04-30 02:45:49

标签: json react-native children

创建了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"
        }
      ]
    }
  ]
}

1 个答案:

答案 0 :(得分:1)

目前您无法按原样访问Parcels

您需要修改树结构,才能以<{p}}的身份访问Parcels

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

并按照此link中所述localhost:3000/PARCELS进行访问,并说明here