在大型嵌套数组中访问JSON属性的值,而无需使用属性名称

时间:2018-09-16 17:46:20

标签: javascript arrays json

这是JSON数组:

    {
  "head": {
    "status": "200",
    "data": {}
  },
  "body": {
    "content": {
      "deliveryMessage": {
        "MT9J2AE/A": {
          "label": "Delivers:",
          "quote": "Sep 23-Sep 24",
          "address": {
            "city": "Ajman"
          },
          "showDeliveryOptionsLink": false,
          "messageType": "Delivery",
          "basePartNumber": "MT9J2",
          "commitCodeId": "8886",
          "idl": false,
          "defaultLocationEnabled": false
        },
        "MT9M2AE/A": {
          "label": "Delivers:",
          "quote": "25 Sep - 2 Oct",
          "address": {
            "city": "Ajman"
          },
          "showDeliveryOptionsLink": false,
          "messageType": "Delivery",
          "basePartNumber": "MT9M2",
          "commitCodeId": "199",
          "idl": false,
          "defaultLocationEnabled": false
        },
        "geoLocated": false,
        "deliveryLocationLink": {
          "text": "Ajman",
          "dataVar": {},
          "newTab": false
        },
        "dudeCookieSet": true,
        "MT9F2AE/A": {
          "label": "Delivers:",
          "quote": "25 Sep - 2 Oct",
          "address": {
            "city": "Ajman"
          },
          "showDeliveryOptionsLink": false,
          "messageType": "Delivery",
          "basePartNumber": "MT9F2",
          "commitCodeId": "199",
          "idl": false,
          "defaultLocationEnabled": false
        },
        "deliveryLocationLabel": "Your delivery location:",
        "WarmAPUWithDude": true,
        "locationCookieValueFoundForThisCountry": true,
        "dudeLocated": true,
        "accessibilityDeliveryOptions": "delivery options",
        "little": true
      }
    }
  }
}

我想访问三个“ quote”属性的值。

到目前为止,这是我所取得的成就:

parsedata = JSON.parse(jsondata);
parsedata[0].body.content.deliveryMessage["MT9J2AE/A"].quote

这将给出“ MT9J2AE / A”的“ quote”值。但是,如果该属性发生更改,如何获得引号?

我的意思是我要问这样的事情:

parsedata[0].body.content.deliveryMessage[0].quote

但这不起作用:(

0 个答案:

没有答案