response json to javascript

response json to javascript

本文关键字:javascript to json response      更新时间:2023-09-26

我有以下json_response:

"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"
        }
      }
    }
  ]
}

我使用以下java脚本提取id

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

问题:如何使用上面的 Java 脚本获取day_low或day_high的值?

谢谢

给定您的实际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)
});

见小提琴