kwhw.net
当前位置:首页 >> php如何解析这种JSON >>

php如何解析这种JSON

$jsonStr = '{"msg":{"auth":"Yes_auth","ddid":"1","payje":0.3,"payzt":"SUCCESS"}}';$arr = json_decode($jsonStr, true);$payzt = $arr['msg']['payzt'];// 或者$jsonStr = '{"msg":{"auth":"Yes_auth","ddid":"1","payje":0.3,"payzt":"SUC...

你这个json转过来还是对象,直接转成数组就好取值了。 $arr = json_decode($str,1); // $str 代表json字符串 转成数组就可以随便取值了。 $lat = $arr['content']['location']['lat']; $ing= $arr['content']['location']['ing'];

转为数组

//使用json_decode函数解码$arr = json_decode($json,true);$number = $arr['number'];

PHP里面有json_encode(数组)可以把数组给转换成JSON字符串, 而json_decode(JSON字符串,boolean)可以把JSON字符串转换成数组或者对象类型,第二个参数boolean默认为false表示对象类型,true表示解析为数组类型通过下表访问

$json=' {"name":"HBuilder","email":"hhhh@163.com","data":[{"name":"aaa","email":"aaaa@163.com","password":"kjkdsjfksd"},{"name":"bbb","email":"bbbb@163.com","password":"bbbb"}]}'$obj = json_decode($json);$data=$obj['data'];prin...

运行结果: 100 200 300 400 500

$jsonStr = '{"msg":{"auth":"Yes_auth","ddid":"1","payje":0.3,"payzt":"SUCCESS"}}'; $arr = json_decode($jsonStr, true); $payzt = $arr['msg']['payzt']; // 或者 $jsonStr = '{"msg":{"auth":"Yes_auth","ddid":"1","payje":0.3,"payzt":...

用json_decode()将json字符串转化成php数组,然后直接循环数组取出值即可。

JSON是通用数据格式,接到传过来的JSON,你可以输出看一下,就是那种格式,很简单,你可以把她转成数组来用

网站首页 | 网站地图
All rights reserved Powered by www.kwhw.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com