所以我试图从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
?>
Echo部分根本不起作用,它什么也没有回复......
我的解码数组看起来像这样,我对roadDamage数组感兴趣,并且地点,时间的值
答案 0 :(得分:0)
print_r($decoded)
将打印所有数组。如果没有打印,那么拼写错误的索引。 BTW更好地将关联数组的索引放在''
答案 1 :(得分:0)
您的索引必须在引号中。否则PHP会查找具有该名称的常量,而不是将其解释为字符串。
变化: echo $ decoding [roadDamage] [0] [place];
要: echo $ decoding ['roadDamage'] [0] ['place'];