json数组解析问题

json数组解析问题,第1张

<?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->contentsecho $b[0]->titleecho '<br>'echo $b[0]->location[0]echo '<br>'echo $b[0]->location[1]?>哎,你这个对象略复杂,我的眼睛都看花了。。。

还有,城市名并没有加密,只是楼上没有指定编码utf-8

城市名是:佛山市

地址是:广东省佛山市禅城区汾江南路8号

省份是:广东省

district是:禅城区

希望能解决您的问题。

存储JSON文档所需的空间与LONGBLOB或LONGTEXT大致相同;存储在JSON列中的任何JSON文档的大小都限制为max_allowed_packet系统变量的值。可以使用JSON_STORAGE_SIZE( )函数获取存储JSON文档所需的空间量。

["ade", 12, null, true, false]

{"k1": "value", "k2": 2}

[99, [78, "e"], {"k1": 1, "k2": "a"}, "de"]

{"k1": 1, "k2": [10, "s"]}

使用JSON路径表达式选择JSON文档中的值。

$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)} } }

这样的数组会取内容了吧


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9558225.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-29
下一篇 2023-04-29

发表评论

登录后才能评论

评论列表(0条)

保存