我正在尝试访问卡片json值,但无济于事。
在我的情景中,我正在向机器人询问“伦敦的天气”,并回复说“它目前在伦敦是9摄氏度”。通过webhook。
这是正确和动态的。
但是,我也试图将值传递给卡片。
在json的回复中,我确实得到了这张卡
{
"id": "REMOVED",
"timestamp": "2017-12-05T11:10:52.033Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "weather in london",
"action": "sayWeather",
"actionIncomplete": false,
"parameters": {
"geo-city": "London"
},
"contexts": [],
"metadata": {
"intentId": "REMOVED",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"webhookResponseTime": 626,
"intentName": "Weather"
},
"fulfillment": {
"speech": "It is currently 9 degrees celcius in London.",
"source": "agent",
"displayText": "It is currently 9 degrees celcius in London.",
"messages": [
{
"type": 0,
"speech": "It is currently 9 degrees celcius in London."
}
],
"data": {
"items": [
{
"simpleResponse": {
"textToSpeech": "This is the first simple response for a basic card"
}
},
{
"basicCard": {
"title": "Title: this is a title",
"formattedText": "This is a basic card. Text in a\n basic card can include \"quotes\" and most other unicode characters\n including emoji . Basic cards also support some markdown\n formatting like *emphasis* or _italics_, **strong** or __bold__,\n and ***bold itallic*** or ___strong emphasis___ as well as other things\n like line \nbreaks",
"subtitle": "This is a subtitle",
"image": {
"url": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
"accessibilityText": "Image alternate text"
},
"buttons": [
{
"title": "This is a button",
"openUrlAction": {
"url": "https://assistant.google.com/"
}
}
]
}
},
{
"simpleResponse": {
"textToSpeech": "This is the 2nd simple response ",
"displayText": "This is the 2nd simple response"
}
}
]
}
},
"score": 1
},
"status": {
"code": 200,
"errorType": "success",
"webhookTimedOut": false
},
"sessionId": "REMOVED"
}
使用data.result.fulfillment.speech
访问语音值可以正常工作。
但是,使用data.result.fulfillment.data.items.basicCard.image.url
时,它不起作用。如果我上升几个级别,我会得到:
[object Object]
感谢您的帮助。
答案 0 :(得分:0)
h1:nth-of-type(0) + * {
display: block;
}
属性是列表而不是对象。因此,您必须使用数字索引来检索数据。在您提供的示例中,<div class="dropdown">
<h1>Title 1</h1>
<ul>
<li>Item 1.1</li>
<li>Item 2.2</li>
<li>Item 3.3</li>
</ul>
<h1>Title 2</h1>
<ul>
<li>Item 2.1</li>
<li>Item 2.2</li>
<li>Item 2.3</li>
</ul>
<h1>Title 3</h1>
<ul>
<li>Item 3.1</li>
<li>Item 3.2</li>
<li>Item 3.3</li>
</ul>
</div>
对象的索引是第二个,因此您的代码应如下所示:
.dropdown {
text-align: left;
color: #00F;
background-color: transparent;
}
h1 {
display: inline-block;
border-top: 1px solid #000;
width: 290px !important;
color: #F00;
font-weight: 500;
border-left: 0;
padding-left: 0;
margin-left: 0;
padding-top: 13px;
line-height: 30px !important;
}
h1 a,
h1 a:visited {
color: #FFFDFD;
}
h1:nth-of-type(0) + * {
display: block;
}
h1 + * {
display: none;
}
h1:hover + *,
h1 + *:hover {
display: block;
}
请注意items
之后的basicCard
。
请记住,如果此列表的顺序发生变化,您可能不再检索data.result.fulfillment.data.items[1].basicCard.image.url
对象,因此您可能需要添加一些检查以确保您正在检索所需的数据。 / p>