如何通过javascript获取深度嵌套的json对象中的任何键的值?

时间:2013-12-12 22:05:08

标签: javascript json

对我的服务器的一个简单的ajax调用给了我这个json对象。如何获取componentName或执行时间的值?

{"data":[{"date":"20131212","time":"103053","componentName":"xxxx","qualityIndexScore":{"noOfLinesOfCode":"47,214","coverage":"61.8%","violations":{"info":"43","minor":"215","major":"19","critical":"98"}},"liveScore":{"noOfErrors":"20313","executionTime":"2938596.2450000006"},"systemHealthScore":{},"dataBaseHealthScore":{}},{"date":"20131211","time":"110504","componentName":"yyyy","qualityIndexScore":{"noOfLinesOfCode":"342","coverage":"1.8%","violations":{"info":"21","minor":"53","major":"3","critical":"2"}},"liveScore":{"noOfErrors":"462","executionTime":"9298.1225000003"},"systemHealthScore":{},"dataBaseHealthScore":{}}]} 

1 个答案:

答案 0 :(得分:0)

取决于您想要的阵列中的哪一个。这是第一组的输出。

console.log(data[0].componentName);
console.log(data[0].liveScore.executionTime);

第二集:

console.log(data[1].componentName);
console.log(data[1].liveScore.executionTime);

依旧......