2016-03-21 90 views
0

我有以下json_response:响应JSON的JavaScript

"list" : { 
    "meta": { 
    "type": "resource-list", 
    "start": 0, 
    "count": 1 
    }, 
    "resources": [ 
    { 
     "resource": { 
     "classname": "Quote", 
     "fields": { 
      "change": "-0.091499", 
      "chg_percent": "-0.790833", 
      "day_high": "11.730000", 
      "day_low": "11.430000", 
      "issuer_name": "J. C. Penney Company, Inc.", 
      "issuer_name_lang": "J. C. Penney Company, Inc.", 
      "name": "J.C. Penney Company, Inc. Holdi", 
      "price": "11.478500", 
      "symbol": "JCP", 
      "ts": "1458576181", 
      "type": "equity", 
      "utctime": "2016-03-21T16:03:01+0000", 
      "volume": "3269312", 
      "year_high": "11.990000", 
      "year_low": "6.000000" 
     } 
     } 
    } 
    ] 
} 

,我提取IDS与以下Java脚本

var name = ''; 

var jsonstr = json_response 
var obj = $.parseJSON(jsonstr); 
$.each(obj, function() { 
    name += name += this['list']['meta']['type']+ "<br/>"; 
}); 
$('#divjson').html(name); 

问题: 我怎样才能得到上面使用day_low的价值或day_high java脚本?

感谢,

回答

1

鉴于您的实际JSON,你可以做这样的:

$.each(x, function(e) { 
    // note that you may need to iterate on the resources property ie: 
    // this.resources.map(function(r) { 
    // r.resource.fields.day_high 
    // } 
    console.log(this.resources[0].resource.fields.day_high) 
    console.log(this.resources[0].resource.fields.day_low) 
}); 

fiddle

+0

感谢YOUE响应。当我doothis我得到以下错误: –

+0

错误:无法获取属性'0'的未定义或空引用 –

+0

对不起,我添加列表到它的前面,它的工作:this.list.resources [0] .resource。 fields.day_high 再次感谢 –