0
我正在使用dojo的arrayUtil.forEach來遍歷我的JSON對象,但是當我到達data.graphs.metrics時,它不會繼續,因爲度量不是數組。我有什麼選擇?JSON格式鑽取問題
xhr("/esp/files/eclwatch/ganglia.json", {
handleAs: "json"
}).then(function(data){
arrayUtil.forEach(data.graphs, function (item, idx) {
//never gets here.
});
});
}
//json file
{
"graphs": [
{
"name": "Bar",
"metrics":{
"metric": ["metric1, metric3"],
"metric": ["metric1", "metric4", "metric5"]
},
"time": ["Hour", "Month", "Week"]
}
]
}
'metrics'是一個對象,它包含兩個同名的鍵。無論如何,你的'1/4/5'條目將覆蓋'1/3'條目。 – 2014-08-27 21:04:08