这个json数据怎么解析

php中文网
发布: 2016-06-13 11:49:55
原创
1170人浏览过

这个json数据如何解析

<br />{"heade":["站次","站名","到时","发时","停留","里程","二等座","一等座","特等座"],"item":[["1","济南西","-","07:05","-","-","-","-","-"],["2","泰安","07:23","07:24","1分","59公里","19.5元","29.5元","-"],["3","曲阜东","07:46","07:53","7分","129公里","39.5元","64.5元","-"],["4","滕州东","08:11","08:13","2分","185公里","54.5元","89.5元","-"],["5","枣庄","08:26","08:28","2分","221公里","69.5元","109.5元","-"],["6","徐州东","08:48","08:50","2分","286公里","89.5元","139.5元","-"],["7","蚌埠南","09:32","09:34","2分","442公里","134元","219元","-"],["8","南京南","10:22","10:24","2分","617公里","189元","304元","-"],["9","镇江南","10:44","10:46","2分","682公里","209元","334元","-"],["10","丹阳北","10:57","10:59","2分","714公里","219元","354元","-"],["11","常州北","11:12","11:14","2分","747公里","229元","369元","-"],["12","无锡东","11:32","11:43","11分","804公里","249元","399元","-"],["13","苏州北","11:54","11:56","2分","831公里","254元","409元","-"],["14","昆山南","12:08","12:10","2分","862公里","263.5元","423.5元","-"],["15","上海虹桥","12:27","-","-","912公里","278.5元","448.5元","-"]],"title":"<B>区间里程:912公里  区间时间:5小时22分</B>"}
登录后复制

这个json数据如何解析才能得到heade、item、title呢
------解决方案--------------------
$json = '{"heade":["站次","站名","到时","发时","停留","里程","二等座","一等座","特等座"],"item":[["1","济南西","-","07:05","-","-","-","-","-"],["2","泰安","07:23","07:24","1分","59公里","19.5元","29.5元","-"],["3","曲阜东","07:46","07:53","7分","129公里","39.5元","64.5元","-"],["4","滕州东","08:11","08:13","2分","185公里","54.5元","89.5元","-"],["5","枣庄","08:26","08:28","2分","221公里","69.5元","109.5元","-"],["6","徐州东","08:48","08:50","2分","286公里","89.5元","139.5元","-"],["7","蚌埠南","09:32","09:34","2分","442公里","134元","219元","-"],["8","南京南","10:22","10:24","2分","617公里","189元","304元","-"],["9","镇江南","10:44","10:46","2分","682公里","209元","334元","-"],["10","丹阳北","10:57","10:59","2分","714公里","219元","354元","-"],["11","常州北","11:12","11:14","2分","747公里","229元","369元","-"],["12","无锡东","11:32","11:43","11分","804公里","249元","399元","-"],["13","苏州北","11:54","11:56","2分","831公里","254元","409元","-"],["14","昆山南","12:08","12:10","2分","862公里","263.5元","423.5元","-"],["15","上海虹桥","12:27","-","-","912公里","278.5元","448.5元","-"]],"title":"<B>区间里程:912公里  区间时间:5小时22分</B>"}';<br />$arr = json_decode($json);<br />var_dump($arr->heade);
登录后复制

------解决方案--------------------
$s = '{"heade":["站次","站名","到时","发时","停留","里程","二等座","一等座","特等座"],"item":[["1","济南西","-","07:05","-","-","-","-","-"],["2","泰安","07:23","07:24","1分","59公里","19.5元","29.5元","-"],["3","曲阜东","07:46","07:53","7分","129公里","39.5元","64.5元","-"],["4","滕州东","08:11","08:13","2分","185公里","54.5元","89.5元","-"],["5","枣庄","08:26","08:28","2分","221公里","69.5元","109.5元","-"],["6","徐州东","08:48","08:50","2分","286公里","89.5元","139.5元","-"],["7","蚌埠南","09:32","09:34","2分","442公里","134元","219元","-"],["8","南京南","10:22","10:24","2分","617公里","189元","304元","-"],["9","镇江南","10:44","10:46","2分","682公里","209元","334元","-"],["10","丹阳北","10:57","10:59","2分","714公里","219元","354元","-"],["11","常州北","11:12","11:14","2分","747公里","229元","369元","-"],["12","无锡东","11:32","11:43","11分","804公里","249元","399元","-"],["13","苏州北","11:54","11:56","2分","831公里","254元","409元","-"],["14","昆山南","12:08","12:10","2分","862公里","263.5元","423.5元","-"],["15","上海虹桥","12:27","-","-","912公里","278.5元","448.5元","-"]],"title":"<B>区间里程:912公里  区间时间:5小时22分</B>"}';<br />if(mb_check_encoding($s, 'gbk')) $s = mb_convert_encoding($s, 'utf-8', 'gbk');<br />print_r(json_decode($s, 1));
登录后复制

Array<br>(<br>    [heade] =&gt; Array<br>        (<br>            [0] =&gt; 站次<br>            [1] =&gt; 站名<br>            [2] =&gt; 到时<br>            [3] =&gt; 发时<br>            [4] =&gt; 停留<br>            [5] =&gt; 里程<br>            [6] =&gt; 二等座<br>            [7] =&gt; 一等座<br>            [8] =&gt; 特等座<br>        )<br><br>    [item] =&gt; Array<br>        (<br>            [0] =&gt; Array<br>                (<br>                    [0] =&gt; 1<br>                    [1] =&gt; 济南西<br>                    [2] =&gt; -<br>                    [3] =&gt; 07:05<br>                    [4] =&gt; -<br>                    [5] =&gt; -<br>                    [6] =&gt; -<br>                    [7] =&gt; -<div class="clear"></div>
登录后复制
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号