【发布时间】:2018-08-09 17:10:29
【问题描述】:
我试图解析 json 对象但遇到了困难。 这就是我想要做的事情
var dat = {array:test};
console.log("testing" + JSON.stringify(dat.array[0]));
for(var i = 0; i < dat.array.length; i++) {
console.log("testing" + JSON.stringify(dat.array[i]));
}
数据位于从数据库获取数据的“测试”变量中。测试对象如下
[ [ { id: 123456,
Key 1: ‘some value’,
Key 2: ‘another value’,
Key 3: 'Frontpage'
} ],
[ { id: 123456,
Key 1: ‘some value’,
Key 2: ‘another value’,
Key 3: 'Frontpage'
} ] ]
我需要针对每个键获得价值。 预期输出
{ id: 123456,
Key 1: ‘some value’,
Key 2: ‘another value’,
Key 3: 'Frontpage'
}
【问题讨论】:
-
能否提供运行代码时的预期输出?
-
更新问题
-
test的数据类型是什么?是 JavaScript 数组还是 JSON 编码的字符串变量? -
javascript 数组
-
“test”中的数据写在上面
标签: json node.js parsing hapijs