2017-12-05 2 views
1

カードのjson値にアクセスしようとしていますが、無駄です。Dialogflow html/js card json value v1

私のシナリオでは、「ロンドンの天気」についてボットに尋ねています。「ロンドンの現在の気温は9度です」と返信します。ウェブフックを介して。

これは正しく、動的です。

しかし、値もカードに渡そうとしています。 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を使用するとうまく動作しません。そして、私はいくつかのレベルをアップして行く場合、私は入手できます:

[オブジェクトのオブジェクト]を

あなたの助けが理解されます。

答えて

0

items属性はリストであり、オブジェクトではありません。そのため、数値索引を使用してデータを取得する必要があります。

data.result.fulfillment.data.items[1].basicCard.image.url

お知らせitems[1]:例では、あなたのコードは次のようになりますので、​​オブジェクトのインデックスが第二提供されます。

このリストの順序が変更された場合、​​オブジェクトを取得できなくなる可能性があるので、いくつかのチェックを追加して、必要なデータを確実に取得したい場合があります。

+0

睡眠不足だと思います。私の愚かさに残念、完全にそれを失った。ハッハッハー。ありがとう! – RSK

+0

問題ありません!お役に立てて嬉しいです。私はこのような間違いを常にしています。 – matthewayne

関連する問題