【发布时间】:2019-09-26 01:02:08
【问题描述】:
我正在处理大量 JSON 数据,并在我的 Nodejs 中使用 Json 流模块来获取值。
这是我的 JSON 结构,我必须从元数据和状态元素中解析和收集 4 或 5 个值。 我在 JSON 数组中有 5 个元素。
request({url:'ssss',verify:'False',headers:{'Authorization':'Bearer zzzz','Accept':'application/json','User-Agent':'zzz'}})
.pipe(JSONStream.parse('items'))
.pipe(es.mapSync(function (data) {
console.log("Data "+data);
console.log("Stringify "+ JSON.stringify(data));
var specificValue = JSON.stringify(data);
console.log("Specific Value"+ specificValue[0].metadata.labels.app);
console.log("Parse and Stringify "+ JSON.parse(JSON.stringify(data)));
})) ;
在console.log Data 我可以看到5 个对象为[object Object],[object Object],[object Object],[object Object],[object Object]
在console.log Stringify 中我只能看到一块(1 个元素)的 JSON 数据,我没有看到所有 5 个元素。
在console.log Specific Value 我看到TypeError: Cannot read property 'labels' of undefined。 label 元素在那里显示日志,查询 specificValue[0].metadata.labels.app 正在其他 JSONPath 测试人员中工作。
使用 JSON Stream 模块后如何解析并获取特定值?
理想情况下,我想做一个for 循环并获取所有值。
在console.log Parse and Stringify 我得到[object Object],[object Object],[object Object],[object Object],[object Object]
【问题讨论】:
标签: javascript arrays node.js json jsonstream