【发布时间】:2014-07-14 04:26:14
【问题描述】:
我想回显/打印一个 JSON 字符串,这是我尝试过的。
我已经解码,因为它返回关联数组。
$decoded = json_decode('{"Title": "The Cuckoos Calling",
"Author": "Robert Galbraith",
"Detail": {
"Publisher": "Little Brown"
}}', true/* returns Associative Array */);
foreach ($decoded as $head => $inner) {
echo $head . ': </br>';
}
它只打印...
Title:
Author:
Detail:
这就是我想要的……
Expected Output :
Title : The Cuckoos Calling
Author : Robert Galbraith
编辑:
它的print_r() 输出是。
Array ( [Title] => The Cuckoos Calling [Author] => Robert Galbraith [Detail] => Array ( [Publisher] => Little Brown ) )
而var_dump() 是
array (size=3)
'Title' => string 'The Cuckoos Calling' (length=19)
'Author' => string 'Robert Galbraith' (length=16)
'Detail' =>
array (size=1)
'Publisher' => string 'Little Brown' (length=12)
【问题讨论】:
-
首先检查
print_r($decoded); -
[可能重复:][1] [1]:stackoverflow.com/questions/9597941/how-to-echo-json-in-php 或者尝试一下。它是一个工作代码