猿问

php 读取 json 里面的字段内容?

php 读取 json 里面的字段内容


Helenr
浏览 1744回答 2
2回答

qq_花开花谢_0

示例代码如下:123456<?phpheader("Content-type:&nbsp;text/html;&nbsp;charset=utf-8");$postArray&nbsp;=&nbsp;'[{"count":{"左脑":2,"右脑":3,"全脑":2,"全脑1":1},"score":{"左脑":8,"右脑":14,"全脑":15,"全脑1":8},"pingjun":{"左脑":4,"右脑":4.6666666666667,"全脑":7.5,"全脑1":8}}]';$de_json&nbsp;=&nbsp;json_decode($postArray,&nbsp;true);echo&nbsp;$de_json[0]['pingjun']['左脑'];?>json 数组结构如图:

精慕HU

参考示例代码如下:<?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/>";}?>运行结果:100200300400500
随时随地看视频慕课网APP

相关分类

Java
我要回答