Jquery 从API反序列化嵌套json

Jquery 从API反序列化嵌套json,jquery,json,api,Jquery,Json,Api,出于某种原因,我无法从这个JSON中提取price变量: { "list": { "meta": { "type": "resource-list", "start": 0, "count": 1 }, "resources": [{ "resource": { "classname": "Quote",

出于某种原因,我无法从这个JSON中提取
price
变量:

{
    "list": {
        "meta": {
            "type": "resource-list",
            "start": 0,
            "count": 1
        },
        "resources": [{
            "resource": {
                "classname": "Quote",
                "fields": {
                    "change": "-0.979900",
                    "chg_percent": "-1.955109",
                    "day_high": "49.290001",
                    "day_low": "48.200001",
                    "issuer_name": "Delta Air Lines, Inc.",
                    "issuer_name_lang": "Delta Air Lines, Inc.",
                    "name": "Delta Air Lines, Inc. Common St",
                    "price": "49.140099",
                    "symbol": "DAL",
                    "ts": "1458663972",
                    "type": "equity",
                    "utctime": "2016-03-22T16:26:12+0000",
                    "volume": "7921714",
                    "year_high": "52.770000",
                    "year_low": "34.610000"
                }
            }
        }]
    }
}

我正在使用:
this.list.resources.resource.fields.price
但它不起作用

resources
是一个数组,因此您需要通过索引访问它:

this.list.resources[0].resource.fields.price;
这显然是假设数组中只有一个条目。如果有多个,则需要在其中循环:

for (var i = 0; i < this.list.resources.length; i++) {
    var price = this.list.resources[i].resource.fields.price;
    // do something with the price here...
}
for(var i=0;i


还注意到,由于这个值是一个价格,您可能需要考虑使用<代码> FutixEclipse(2)< /代码>将其强制为2个小数点,但是请注意,这会强制该类型为字符串,因此确保事先对其进行任何计算。

是的,Rory是正确的。list.resources[0].resource.fields.price应该可以工作。我添加了数组括号,但可能键入了错误。