如何从此JSON数据中的第二个元素获取第一个值?

时间:2016-12-01 08:06:02

标签: javascript html json return-value

我有2个收集FailedCount和SucceededCount的JSON。

{
 "FailedCount": [{
    "FailedCount_DATE_CURRENT_CHECK": "2016-11-30 10:40:09.0",
    "FailedCount_DATE__CURRENT__CHECK": "10:40:09",
    "FailedCount_MEAS_VALUE": 0
  }, {
    "FailedCount_DATE_CURRENT_CHECK": "2016-11-30 10:45:09.0",
    "FailedCount_DATE__CURRENT__CHECK": "10:45:09",
    "FailedCount_MEAS_VALUE": 0
  }, {
    "FailedCount_DATE_CURRENT_CHECK": "2016-11-30 10:50:09.0",
    "FailedCount_DATE__CURRENT__CHECK": "10:50:09",
    "FailedCount_MEAS_VALUE": 1
  }],
  "SucceededCount": [{
    "SucceededCount_MEAS_VALUE": 555
  }, {
    "SucceededCount_MEAS_VALUE": 547
  }, {
    "SucceededCount_MEAS_VALUE": 339
  }]
}

如何获得第一个值SucceededCount

我试过了:

jsonObj.SucceededCount[1];

但结果并不好:[object Object]

2 个答案:

答案 0 :(得分:0)

试试这个

jsonObj.SucceededCount[0].SucceededCount_MEAS_VALUE;

希望这有帮助。

答案 1 :(得分:0)

获取对象的属性SucceededCount。你现在有一个数组。获取此数组SucceededCount[0]的第一个对象,然后选择所需的属性SucceededCount[0].SucceededCount_MEAS_VALUE



var obj = {
  "FailedCount": [{
    "FailedCount_DATE_CURRENT_CHECK": "2016-11-30 10:40:09.0",
    "FailedCount_DATE__CURRENT__CHECK": "10:40:09",
    "FailedCount_MEAS_VALUE": 0
  }, {
    "FailedCount_DATE_CURRENT_CHECK": "2016-11-30 10:45:09.0",
    "FailedCount_DATE__CURRENT__CHECK": "10:45:09",
    "FailedCount_MEAS_VALUE": 0
  }, {
    "FailedCount_DATE_CURRENT_CHECK": "2016-11-30 10:50:09.0",
    "FailedCount_DATE__CURRENT__CHECK": "10:50:09",
    "FailedCount_MEAS_VALUE": 1
  }],
  "SucceededCount": [{
    "SucceededCount_MEAS_VALUE": 555
  }, {
    "SucceededCount_MEAS_VALUE": 547
  }, {
    "SucceededCount_MEAS_VALUE": 339
  }]
};

console.log(obj.SucceededCount[0].SucceededCount_MEAS_VALUE);