0

I have the following 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"
        }
      }
    }
  ]
}

and I extract ids with following java script

var name = '';

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

QUESTION: how can I get the value of day_low or day_high using above java script?

Thanks,

Dave
  • 10,748
  • 3
  • 43
  • 54
James KM
  • 69
  • 8

1 Answers1

1

Given your actual JSON, you can do it like this:

$.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)
});

See fiddle

cl3m
  • 2,791
  • 19
  • 21