我使用NodeJS向REST服务器发出请求,并在我的“ body”中获取此类型的JSON
[{
"id": 802,
"created": "2016-10-18 15:22:08",
"test": {
"name": "Fred "
}
}]
用JSON.parse记录我的身体,这对于JSON的“根”来说工作正常,但是我在“测试”数组中没有得到“名称”
var jsonObj = JSON.parse(body);
for(index in jsonObj) {
console.log(jsonObj[index].bag);
我该如何进行循环以及是否有“测试”将数据密钥取出?
给定您的JSON描述,此代码应该可以工作
var jsonObj = JSON.parse(body);
for(index in jsonObj) {
console.log(jsonObj[index].test.name);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句