【发布时间】:2015-08-07 12:50:45
【问题描述】:
我是 Node.JS 的新手,我能够解析 JSON 数据并执行控制台日志以打印出名称和徽章。
var details = JSON.parse(body);
console.log(details.name, details.badges.length);
但我不知道如何获取 bagdes 数组中的数据,例如 id、name、url。
我试过了
console.log(details.badges.length.id);
但是什么都没有出现。我怎样才能访问它?谢谢。
{
"name": "Andrew Chalkley",
"badges": [
{
"id": 49,
"name": "Newbie",
"url": "http:\/\/teamtreehouse.com\/chalkers",
"icon_url": "https:\/\/achievement-images.teamtreehouse.com\/Generic_Newbie.png",
"earned_date": "2012-07-23T19:59:34.000Z",
"courses": [
]
},
{
"id": 26,
"name": "Introduction",
"url": "http:\/\/teamtreehouse.com\/library\/html\/introduction",
"icon_url": "https:\/\/achievement-images.teamtreehouse.com\/HTML_Basics.png",
"earned_date": "2012-07-23T21:57:24.000Z",
"courses": [
{
"title": "HTML",
"url": "http:\/\/teamtreehouse.com\/library\/html",
"badge_count": 1
},
{
"title": "Introduction",
"url": "http:\/\/teamtreehouse.com\/library\/html\/introduction",
"badge_count": 1
}
]
}
}
【问题讨论】:
标签: arrays json node.js dictionary