如何在 PHP 中显示 Json 数据


How to display Json Data in PHP?

我有以下JSON数据,我尝试使用PHP显示Json数据,但它没有显示结果。这是我的 JSON 数据

$ads={"ReferenceNo":"KWPOG0QoXU","Message":"SUCCESS","Status":1,"ResponseStatus":200}

我尝试遵循代码,但它不起作用。

$ads1 = json_decode($ads);
echo $ads1->ReferenceNo;

请帮助我如何在 PHP 中显示结果。提前谢谢。

你应该将数据解析为字符串,然后像这样做:

$json = '{"ReferenceNo":"KWPOG0QoXU","Message":"SUCCESS","Status":1,"ResponseStatus":200}';
$array = json_decode($json, true);
echo '<pre>'; print_r($array);

输出:

Array
(
    [ReferenceNo] => KWPOG0QoXU
    [Message] => SUCCESS
    [Status] => 1
    [ResponseStatus] => 200
)

若要获取数据,请按如下方式编写代码:

echo $array['ReferenceNo'];

让我知道以获得进一步的帮助。

对于有兴趣从某个位置提取数据的用户,请使用以下命令,而不是在文件上添加 json;

   $json = file_get_contents('MYLOCATION.json');
   $array = json_decode($json, true);
   echo '<pre>'; print_r($array);

快乐的编码:)