1
我是Json对象和Json数组中的新手。我想访问Json对象中的嵌套对象,但是我犯了一个小错误,我浪费了2小时的时间搜索,也在阅读大量的stackoverflow的问题,但是我找不到我犯的错误。请帮我出Json中的嵌套对象
响应
{ __v: 0,
friends_in:
[ { friends_in_email: '12',
friends_in_gcm_regId: '12'
} ]
}
我的代码
console.log(JSON.stringify(doc));
输出:
{
"__v": " 0",
"friends_in": [
{
"friends_in_email": "12",
"friends_in_gcm_regId": "12"
}
]
}
下面是错误发生说不确定
mycode的
console.log(JSON.stringify(doc[0].__v));
console.log(JSON.stringify(doc[0].friends_in));
输出
0 //Correct
undefined //Why ?
非常感谢,我看到你已经使用JSON.parse()来这是在使用解析一个JSON,这帮助我访问“friends_in_email” –