javascript - 无法使用 echo 查看输出

标签 javascript php json echo

Array
(
    [id] => 9794ea5d-9dc1-4b15-a798-fd0fa4ff6f4c
    [timestamp] => 2017-07-05T03:47:00.764Z
    [lang] => en
    [result] => Array
        (
            [source] => agent
            [resolvedQuery] => what is annual leave
            [speech] => 
            [action] => test
            [actionIncomplete] => 
            [parameters] => Array
                (
                    [allowance_type] => Array
                        (
                        )

                    [bonus_type] => Array
                        (
                        )

                    [salary_type] => Array
                        (
                        )

                    [leave_type] => Array
                        (
                            [0] => annual leave
                        )

                )

            [contexts] => Array
                (
                    [0] => Array
                        (
                            [name] => to-apply
                            [parameters] => Array
                                (
                                    [allowance_type] => Array
                                        (
                                        )

                                    [leave_type] => Array
                                        (
                                            [0] => annual leave
                                        )

                                    [bonus_type.original] => 
                                    [bonus_type] => Array
                                        (
                                        )

                                    [leave_type.original] => annual leave
                                    [allowance_type.original] => 
                                    [salary_type] => Array
                                        (
                                        )

                                    [salary_type.original] => 
                                )

                            [lifespan] => 5
                        )

                )

            [metadata] => Array
                (
                    [intentId] => e2bda510-2f4d-41b8-a80b-e11f148c804b
                    [webhookUsed] => true
                    [webhookForSlotFillingUsed] => false
                    [intentName] => description-definition-what
                )

            [fulfillment] => Array
                (
                    [speech] => 
                    [messages] => Array
                        (
                            [0] => Array
                                (
                                    [type] => 0
                                    [speech] => 
                                )

                        )

                )

            [score] => 1
        )

    [status] => Array
        (
            [code] => 200
            [errorType] => success
        )

    [sessionId] => 07a5acce-9587-4f06-b715-1c9106732109
)

您好,我有这段代码,我试图创建一个 webhook 来从 API.AI 调用 json 文件。它获取数据并保存在一个名为 JSON.php 的新文件中,但我试图回显它没有发生的数据。是因为页面没有自动刷新还是?

<?php

$data = json_decode(file_get_contents("php://input"), true);
file_put_contents("JSON.php", print_r($data, true));

echo $data['intentName'];

?>

最佳答案

所以应该是$data['result']['metadata']['intentName'];而不是$data['intentName']

关于javascript - 无法使用 echo 查看输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44916402/

相关文章:

java - FLAT JSON ARRAY 到带有 Jackson JSON lib 的 Bean 列表

javascript - 什么可以使 dojo 上的文本输入/选择位于一切之上?

javascript - 数组到多个字符串

PHP 函数中的 javaScript 代码仅在第一次调用时有效

php - MySQL:选择列包含列表中元素的行

ruby-on-rails - 哈希 to_json : how can I skip the key and list only the values in the JSON response?

javascript - Web进程绑定(bind)$port节点失败

javascript - 清除输入事件 - HTML 和 JavaScript

php - 获取 mysql 资源字符串的第一行?

json - fbexternal-a.akamaihd.net/safe_image.php 返回 1x1 图像