php解析json数组问题。
从json格式数据{"status":0,"total":1,"size":1,"contents":[{"title":"111","location":[113.11...
从json格式数据
{"status":0,"total":1,"size":1,"contents":[{"title":"111","location":[113.11509,23.012777],"city":"\u4f5b\u5c71\u5e02","create_time":1385386545,"geotable_id":38432,"address":"\u5e7f\u4e1c\u7701\u4f5b\u5c71\u5e02\u7985\u57ce\u533a\u6c7e\u6c5f\u5357\u8def8\u53f7","province":"\u5e7f\u4e1c\u7701","district":"\u7985\u57ce\u533a","map_id":"1","uid":42504634,"coord_type":3,"type":0,"distance":370,"weight":0}]}
中,捉取title的值定义$title location经纬度定义 $location_X $location_Y distance的值定义$distance
PHP菜鸟在线等 展开
{"status":0,"total":1,"size":1,"contents":[{"title":"111","location":[113.11509,23.012777],"city":"\u4f5b\u5c71\u5e02","create_time":1385386545,"geotable_id":38432,"address":"\u5e7f\u4e1c\u7701\u4f5b\u5c71\u5e02\u7985\u57ce\u533a\u6c7e\u6c5f\u5357\u8def8\u53f7","province":"\u5e7f\u4e1c\u7701","district":"\u7985\u57ce\u533a","map_id":"1","uid":42504634,"coord_type":3,"type":0,"distance":370,"weight":0}]}
中,捉取title的值定义$title location经纬度定义 $location_X $location_Y distance的值定义$distance
PHP菜鸟在线等 展开
3个回答
展开全部
$a = json_decode('{"status":0,"total":1,"size":1,"contents":[{"title":"111","location":[113.11509,23.012777],"city":"\u4f5b\u5c71\u5e02","create_time":1385386545,"geotable_id":38432,"address":"\u5e7f\u4e1c\u7701\u4f5b\u5c71\u5e02\u7985\u57ce\u533a\u6c7e\u6c5f\u5357\u8def8\u53f7","province":"\u5e7f\u4e1c\u7701","district":"\u7985\u57ce\u533a","map_id":"1","uid":42504634,"coord_type":3,"type":0,"distance":370,"weight":0}]}',true);
json_decode第二个参数true
解析出来就是array(4) { ["status"]=> int(0) ["total"]=> int(1) ["size"]=> int(1) ["contents"]=> array(1) { [0]=> array(14) { ["title"]=> string(3) "111" ["location"]=> array(2) { [0]=> float(113.11509) [1]=> float(23.012777) } ["city"]=> string(9) "佛山市" ["create_time"]=> int(1385386545) ["geotable_id"]=> int(38432) ["address"]=> string(43) "广东省佛山市禅城区汾江南路8号" ["province"]=> string(9) "广东省" ["district"]=> string(9) "禅城区" ["map_id"]=> string(1) "1" ["uid"]=> int(42504634) ["coord_type"]=> int(3) ["type"]=> int(0) ["distance"]=> int(370) ["weight"]=> int(0) } } }
这样的数组会取内容了吧
json_decode第二个参数true
解析出来就是array(4) { ["status"]=> int(0) ["total"]=> int(1) ["size"]=> int(1) ["contents"]=> array(1) { [0]=> array(14) { ["title"]=> string(3) "111" ["location"]=> array(2) { [0]=> float(113.11509) [1]=> float(23.012777) } ["city"]=> string(9) "佛山市" ["create_time"]=> int(1385386545) ["geotable_id"]=> int(38432) ["address"]=> string(43) "广东省佛山市禅城区汾江南路8号" ["province"]=> string(9) "广东省" ["district"]=> string(9) "禅城区" ["map_id"]=> string(1) "1" ["uid"]=> int(42504634) ["coord_type"]=> int(3) ["type"]=> int(0) ["distance"]=> int(370) ["weight"]=> int(0) } } }
这样的数组会取内容了吧
推荐于2016-10-03 · 知道合伙人软件行家
关注
展开全部
<?php
$a = json_decode('{"status":0,"total":1,"size":1,"contents":[{"title":"111","location":[113.11509,23.012777],"city":"\u4f5b\u5c71\u5e02","create_time":1385386545,"geotable_id":38432,"address":"\u5e7f\u4e1c\u7701\u4f5b\u5c71\u5e02\u7985\u57ce\u533a\u6c7e\u6c5f\u5357\u8def8\u53f7","province":"\u5e7f\u4e1c\u7701","district":"\u7985\u57ce\u533a","map_id":"1","uid":42504634,"coord_type":3,"type":0,"distance":370,"weight":0}]}');
$b = $a->contents;
echo $b[0]->title;
echo '<br>';
echo $b[0]->location[0];
echo '<br>';
echo $b[0]->location[1];
?>
哎,你这个对象略复杂,我的眼睛都看花了。。。
还有,城市名并没有加密,只是楼上没有指定编码utf-8
城市名是:佛山市
地址是:广东省佛山市禅城区汾江南路8号
省份是:广东省
district是:禅城区
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
json_decode($json);解析一下,不过里面city字段是加密过的,要看是什么方式加密的
追问
不需要读取city字段,求详细示例~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询