无法访问 json 文件中的部分
can't reach to section in json file
我正在尝试检索 json
文件的自适应卡片中的选择。
所以当过敏选项'peanut'
被选中时,我想把它赋值给一个变量。但是代码一直报错。
适配卡码:
{
"type": "message",
"speak": "...",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Almost there...",
"size": "large",
"weight": "bolder"
}
],
"actions": [
{
"type": "Action.ShowCard",
"title": "Beef",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "What are you allergic to?",
"size": "medium",
"wrap": true
},
{
"type": "Input.ChoiceSet",
"value": "BeefAllergy",
"id": "BeefAllergy",
"style": "expanded",
"isMultiSelect": false,
"isCompact": false,
"choices": [
{
"title": "Peanut",
"value": "peanut"
},
{
"title": "Seafood",
"value": "seafood"
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Next",
"data": {
"mealOptions": "beef"
}
}
]
}
}
]
}
}
]
}
以下是我尝试将其存储在变量中的方法:
lunchAllergy= session.message.attachments.content.actions.card.body[1].choices[1].value
session.send(lunchallergy)
这是错误:
ERROR: Cannot read property 'actions' of undefined
在我对你的自适应卡片内容的测试中,实际上,当你的用户点击 Action.Submit
按钮时,你的机器人可以在 session.message.value
中获得用户选择,你可以将你想要的存储在变量。
详情请参考https://github.com/Microsoft/BotBuilder-Samples/blob/master/Node/cards-AdaptiveCards/app.js中的示例。
我正在尝试检索 json
文件的自适应卡片中的选择。
所以当过敏选项'peanut'
被选中时,我想把它赋值给一个变量。但是代码一直报错。
适配卡码:
{
"type": "message",
"speak": "...",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Almost there...",
"size": "large",
"weight": "bolder"
}
],
"actions": [
{
"type": "Action.ShowCard",
"title": "Beef",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "What are you allergic to?",
"size": "medium",
"wrap": true
},
{
"type": "Input.ChoiceSet",
"value": "BeefAllergy",
"id": "BeefAllergy",
"style": "expanded",
"isMultiSelect": false,
"isCompact": false,
"choices": [
{
"title": "Peanut",
"value": "peanut"
},
{
"title": "Seafood",
"value": "seafood"
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Next",
"data": {
"mealOptions": "beef"
}
}
]
}
}
]
}
}
]
}
以下是我尝试将其存储在变量中的方法:
lunchAllergy= session.message.attachments.content.actions.card.body[1].choices[1].value
session.send(lunchallergy)
这是错误:
ERROR: Cannot read property 'actions' of undefined
在我对你的自适应卡片内容的测试中,实际上,当你的用户点击 Action.Submit
按钮时,你的机器人可以在 session.message.value
中获得用户选择,你可以将你想要的存储在变量。
详情请参考https://github.com/Microsoft/BotBuilder-Samples/blob/master/Node/cards-AdaptiveCards/app.js中的示例。