php 将json转成数组 并 echo array
可以使用php内置函数json_decode将json字符串转换为php数组,示例代码如下:
$json_str = '{"name":"Tom","age":18}';
$array = json_decode($json_str, true);
echo '<pre>';
print_r($array);
echo '</pre>';
其中,json_decode函数的第二个参数设置为true,表示要将json字符串转换为关联数组。输出结果如下:
Array
(
[name] => Tom
[age] => 18
)
需要注意的是,如果json字符串格式不正确或者无法解析,则json_decode函数会返回null。
原文地址: https://www.cveoy.top/t/topic/cKnz 著作权归作者所有。请勿转载和采集!