当前位置:Gxlcms > PHP教程 > 这个json数据怎么解析

这个json数据怎么解析

时间:2021-07-01 10:21:17 帮助过:4人阅读

这个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":"区间里程:912公里 区间时间:5小时22分"}

这个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":"区间里程:912公里  区间时间:5小时22分"}';
$arr = json_decode($json);
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":"区间里程:912公里  区间时间:5小时22分"}';
if(mb_check_encoding($s, 'gbk')) $s = mb_convert_encoding($s, 'utf-8', 'gbk');
print_r(json_decode($s, 1));
Array
(
[heade] => Array
(
[0] => 站次
[1] => 站名
[2] => 到时
[3] => 发时
[4] => 停留
[5] => 里程
[6] => 二等座
[7] => 一等座
[8] => 特等座
)

[item] => Array
(
[0] => Array
(
[0] => 1
[1] => 济南西
[2] => -
[3] => 07:05
[4] => -
[5] => -
[6] => -
[7] => -

人气教程排行