admin管理员组文章数量:1310315
I have a JSON string that looks like this:
{
"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]
]
}
]
}
Every time I try to parse it, I use code like this:
var data = JSON.parse(json);
console.log(data);
And the following is what is printed to the console:
{
"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]
}
]
}
I've tried a couple of things, but how can I get the data in the rows
field? After parsing, the console just shows [Object]
.
I have a JSON string that looks like this:
{
"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]
]
}
]
}
Every time I try to parse it, I use code like this:
var data = JSON.parse(json);
console.log(data);
And the following is what is printed to the console:
{
"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]
}
]
}
I've tried a couple of things, but how can I get the data in the rows
field? After parsing, the console just shows [Object]
.
2 Answers
Reset to default 9The output you're seeing is just the way it's being displayed. If you access data.rowsets[0].rows
, you can see that the JSON was indeed successfully parsed. You can also use util.inspect()
when specifying the depth
property to tell Node.js to recurse deeper when formatting the object.
Here is an example using util.inspect()
:
var data = JSON.parse(json);
// a null depth means to recurse indefinitely
console.log(util.inspect(data, { depth: null }));
Have tested your code. It's fine.
var a = {
"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 util = require('util');
console.log(util.inspect(a.rowsets[0].rows, { showHidden: true, depth: null }));
本文标签: javascriptNodejs JSON parsingStack Overflow
版权声明:本文标题:javascript - Node.js JSON parsing - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741828495a2399789.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论