dtjzpg5313 2018-11-12 19:10
浏览 58
已采纳

too long

Using php, how can I fetch specific data from dialogflow fulfillment JSON request and store the data into a php variable?

Here is the JSON response I 'm getting from my dialogflow agent

{
  "responseId": "e9106589-2a41-47c4-bdde-8f3cee8f40da",
  "queryResult": {
    "queryText": "switch on cfl",
    "action": "input.switchoncfl",
    "parameters": {
      "makeRequest": "cfl_on"
    },
    "allRequiredParamsPresent": true,
    "fulfillmentMessages": [
      {
        "platform": "ACTIONS_ON_GOOGLE",
        "simpleResponses": {
          "simpleResponses": [
            {
              "textToSpeech": "Sure. Turning CFL on... Anything else can I help you with?",
              "displayText": "Sure. Turning CFL on..."
            }
          ]
        }
      }
    ],
    "intent": {
      "name": "projects/smarthome-cf277/agent/intents/5be27f38-105d-4854-b62d-ec3a6de80cc7",
      "displayName": "1.1-Switch_on_CFL"
    },
    "intentDetectionConfidence": 1,
    "languageCode": "en"
  },
  "originalDetectIntentRequest": {
    "payload": {}
  },
  "session": "projects/smarthome-cf277/agent/sessions/ca0261aa-913f-96f1-b5aa-7755637d5ab7"
}

And here is my php code

<?php
    header("Content-Type: application/json");
    ob_start();
    $content = json_decode(file_get_contents('php://input'),true);
    $action = $content['parameters']['makeRequest'];
    ob_end_clean();
?>

I want to store cfl_on value to $action variable. How can I do that? this php code does not work.

  • 写回答

1条回答 默认 最新

  • drne47241 2018-11-12 19:12
    关注

    You just missed out the "queryResult" layer of the object.

    $action = $content['queryResult']['parameters']['makeRequest'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算