我有一個JSON字符串,看起來像這樣:Node.js的JSON解析
{
"resultType" : "history",
"currentTime" : "2011-10-22T15:46:00+00:00",
"columns" : ["date","orders","quantity","low","high","average"],
"rowsets" : [
{
"generatedAt" : "2011-10-22T15:42:00+00:00",
"rows" : [
["2011-12-03T00:00:00+00:00",40,40,1999,499999.99,35223.50],
["2011-12-02T00:00:00+00:00",83,252,9999,11550,11550]
]
}
]
}
每次我嘗試分析它,我用這樣的代碼:
var data = JSON.parse(json);
console.log(data);
而下面什麼是打印到控制檯:
{
"resultType" : "history",
"currentTime" : "2011-10-22T15:46:00+00:00",
"columns" : ["date","orders","quantity","low","high","average"],
"rowsets" : [
{
"generatedAt" : "2011-10-22T15:42:00+00:00",
"rows" : [Object]
}
]
}
我已經試過幾件事情,但我怎樣才能在rows
字段中的數據?解析後,控制檯只顯示[Object]
。
您可以使用'data.rowsets [0] .rows'來訪問它。 'rowsets'是一個數組。 – Rowno
這與陣列括號完成了這個訣竅。謝謝! – user637980