php 读取 json 里面的字段内容
2 回答
qq_花开花谢_0
TA贡献1835条经验 获得超7个赞
示例代码如下:
123456 | <?php header( "Content-type: text/html; charset=utf-8" ); $postArray = '[{"count":{"左脑":2,"右脑":3,"全脑":2,"全脑1":1},"score":{"左脑":8,"右脑":14,"全脑":15,"全脑1":8},"pingjun":{"左脑":4,"右脑":4.6666666666667,"全脑":7.5,"全脑1":8}}]' ; $de_json = json_decode( $postArray , true); echo $de_json [0][ 'pingjun' ][ '左脑' ]; ?> |
json 数组结构如图:
精慕HU
TA贡献1845条经验 获得超8个赞
参考示例代码如下:
<?php
$json = '{"a":100,"b":200,"c":300,"d":400,"e":500}';
//首先将json字符串转换成关联数组
$arr=json_decode($json, true);
//然后循环读取数据
foreach($arr as $item){
echo $item;
echo "<br/>";
}
?>
运行结果:
100
200
300
400
500
添加回答
举报
0/150
提交
取消