我有一个json响应,如下面的
[{"record_type":"type1","record_name":"name1"},
{"record_type":"type2","record_name":"name2"}]
希望得到如下的输出。
type1 name1
type2 name2
我是json和php的初学者。伙计们请帮忙;)
答案 0 :(得分:0)
试试这个..
<?php
$jsonData = '[{"record_type":"type1","record_name":"name1"},
{"record_type":"type2","record_name":"name2"}]';
$phpArray = json_decode($jsonData);
print_r($phpArray);
foreach ($phpArray as $key => $value) {
echo "<p>$value->record_type | $value->record_name</p>";
}
?>
答案 1 :(得分:0)
尝试以下方法:
<?php
$json = '[{"record_type":"type1","record_name":"name1"},
{"record_type":"type2","record_name":"name2"}]';
$decodedJson = json_decode($json,true);
foreach ($decodedJson as $value) {
echo $value['record_type']." ".$value['record_name'];
echo "<br>";
}
?>
这将返回如下结果:
type1 name1
type2 name2
答案 2 :(得分:-2)
use:
<?php
json_decode($json_str);
?>