【发布时间】:2021-04-15 05:15:02
【问题描述】:
以下是我的 json 数据:
{
"code": "200",
"count": 3,
"data": [
{
"_id": "602a2d4427e5ac1f5c8e897b",
"survey_id": "602a5de91d4f0000ec004b94",
"parent_question_id": "",
"is_required": "1",
"is_active": "1",
"options": [
{
"_id": "604b22c53b57d53fdc8c43f3",
"question_id": "602a2d4427e5ac1f5c8e897b",
"option_type_id": "602a2b0127e5ac1f5c8e8976",
"option_details": "He/She is good.",
"is_active": "1"
},
{
"_id": "604b22df3b57d53fdc8c43f5",
"question_id": "602a2d4427e5ac1f5c8e897b",
"option_type_id": "602a2b0127e5ac1f5c8e8976",
"option_details": "He/She is Average.",
"is_active": "1"
},
{
"_id": "604b22e63b57d53fdc8c43f6",
"question_id": "602a2d4427e5ac1f5c8e897b",
"option_type_id": "602a2b0127e5ac1f5c8e8976",
"option_details": "He/She is Poor.",
"is_active": "1"
},
{
"_id": "604b22d33b57d53fdc8c43f4",
"question_id": "602a2d4427e5ac1f5c8e897b",
"option_type_id": "602a2b0127e5ac1f5c8e8976",
"option_details": "He/She is Excellent.",
"is_active": "1"
}
],
"qustion_type": {
"_id": "602a2b2627e5ac1f5c8e8978",
"question_type": "Multie Radio",
"is_active": "1"
}
},
]
}
这里我想获取“option”数组中的“option_details”的数据。我可以得到选项数组。
以下是我的代码:
return
axios.get(api call here)
.then((results) => {
results.data.data.map(quesobj => {
ques.push(quesobj.question_text);
})
console.log(ques);
results.data.data.map(questypeobj => {
questype.push(questypeobj.qustion_type.question_type);
})
results.data.data.map(optionobj => {
option.push(optionobj.options);
})
console.log("Hello");
console.log(option);
console.log(option[0]);
console.log(option[0].option_details);
conv.add('Thank you');
})
在控制台中,当我打印选项时,它会显示来自 api 的选项数组。但是当我打印 option[0] 时,它会出现 [] 而当我打印 option[0].option_details 时,它会出现未定义。我该如何解决?
有人可以帮我解决这个问题吗?
【问题讨论】:
标签: node.js actions-on-google dialogflow-es-fulfillment