0

所以我试图从 json_decode 回显数组数据,我尝试了几种方法,但似乎没有任何效果,如何正确执行此操作?

这是我的代码:

<?php
$jsonstring = file_get_contents('example.com/json'); //get the string
$decoded = json_decode($jsonstring, true);   //decode the string
echo $decoded[roadDamage][0][place]; //echo array content
?>

回声部分根本不起作用,它什么都没有回声......

我的解码数组看起来像这样,我对 roadDamage 数组和地点、时间的值很感兴趣

4

2 回答 2

0
print_r($decoded)

将打印您的所有数组。如果没有打印任何内容,那么您拼写错误的索引。顺便说一句,最好将关联数组的索引放入''

于 2013-02-20T14:42:03.297 回答
0

您的索引需要用引号引起来。否则,PHP 会查找具有该名称的常量,而不是将其解释为字符串。

更改: echo $decoded[roadDamage][0][place];

To: echo $decoded['roadDamage'][0]['place'];

于 2013-02-20T14:46:37.263 回答