2013-12-12 51 views
0

簡單的ajax調用我的服務器給了我這個json對象。如何獲取componentName的值或執行時間?如何通過JavaScript獲取深度嵌套的json對象中的任何鍵的值?

{"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":{}}]} 
+0

'obj.data'是對象的數組。所以,第一個是'obj.data [0] .componentName'。 –

+0

[Access/process(嵌套)對象,數組或JSON]可能的重複(http://stackoverflow.com/questions/11922383/access-process-nested-objects-arys-or-json) –

回答

0

取決於你想要的數組中的哪一個。這是第一組的輸出。

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

第二組:

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

等等...

相關問題