如何显示JSON数组

时间:2017-07-04 07:46:20

标签: php arrays json

所以我编写了这段代码来从API.AI获取json。我想知道如何在此表单上回显解码的JSON文件。目前解码的JSON正在保存在新文件JSON.php中,但是我想知道如何查看它而不是保存?

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

2 个答案:

答案 0 :(得分:0)

当注释声明你可以使用var_dump来查看粗略数据,但如果你真的想用它来做某些东西,你可能想要遍历对象和extracte属性。

像这样:

foreach($data as $theData)
{
 echo $theData->property;
}

此致

答案 1 :(得分:0)

这样做: -

$ postdata = file_get_contents(" php:// input");

$ request = json_decode($ postdata);

的print_r($请求);

或者你可以这样做: - $ request-> indexname