jQuery将JSON响应中的数组拉入新变量

时间:2017-10-30 03:05:15

标签: javascript jquery arrays json

提前感谢您的帮助。我正在使用一个插件,它期望JSON响应是一个数组而不是一个对象。下面是我正在获得的JSON响应的示例

{
    "instruments": [
        {
            "id": 3316,
            "code": "WES",
            "market_code": "ASX",
            "name": "Wesfarmers Limited",
            "currency_code": "AUD",
            "pe_ratio": 16.38,
            "nta": 4.44,
            "eps": 2.55,
            "current_price": 41.78,
            "current_price_updated_at": "2017-10-26T16:10:09.000+11:00",
            "sector_classification_name": "Retail Trade",
            "industry_classification_name": "Food Retail",
            "security_type": "Ordinary Shares",
            "registry_name": "Computershare"
        },
        {
            "id": 2955,
            "code": "RIO",
            "market_code": "ASX",
            "name": "Rio Tinto Limited",
            "currency_code": "AUD",
            "pe_ratio": 14.95,
            "nta": 27.77,
            "eps": 4.66,
            "current_price": 69.66,
            "current_price_updated_at": "2017-10-26T16:10:11.000+11:00",
            "sector_classification_name": "Non-Energy Minerals",
            "industry_classification_name": "Other Metals/Minerals",
            "security_type": "Ordinary Shares",
            "registry_name": "Computershare"
        },

    ],
    "links": {}
}

我需要将其引入其自己的JSON对象的数组是instruments数组。

现在通常我知道我会通过(如果响应变量被称为数据)访问该数据data.instruments [0] .name作为一个例子,它会给我Wesfarmers有限的

但如果我想让整个数组都放在一个新的变量中,然后可以解析它,我怎么能让它发生呢?

干杯

1 个答案:

答案 0 :(得分:0)

arr=new Array(data.instruments)
相关问题