无法使用echo查看输出

时间:2017-07-05 03:02:16

标签: 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'];

?>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

因此它应该是$data['result']['metadata']['intentName'];而不是$data['intentName']