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

这个json数据如何解析

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

{"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呢


回复讨论(解决方案)

{"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":[["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] => -                    [8] => -                )            [1] => Array                (                    [0] => 2                    [1] => 泰安                    [2] => 07:23                    [3] => 07:24                    [4] => 1分                    [5] => 59公里                    [6] => 19.5元                    [7] => 29.5元                    [8] => -                )            [2] => Array                (                    [0] => 3                    [1] => 曲阜东                    [2] => 07:46                    [3] => 07:53                    [4] => 7分                    [5] => 129公里                    [6] => 39.5元                    [7] => 64.5元                    [8] => -                )            [3] => Array                (                    [0] => 4                    [1] => 滕州东                    [2] => 08:11                    [3] => 08:13                    [4] => 2分                    [5] => 185公里                    [6] => 54.5元                    [7] => 89.5元                    [8] => -                )            [4] => Array                (                    [0] => 5                    [1] => 枣庄                    [2] => 08:26                    [3] => 08:28                    [4] => 2分                    [5] => 221公里                    [6] => 69.5元                    [7] => 109.5元                    [8] => -                )            [5] => Array                (                    [0] => 6                    [1] => 徐州东                    [2] => 08:48                    [3] => 08:50                    [4] => 2分                    [5] => 286公里                    [6] => 89.5元                    [7] => 139.5元                    [8] => -                )            [6] => Array                (                    [0] => 7                    [1] => 蚌埠南                    [2] => 09:32                    [3] => 09:34                    [4] => 2分                    [5] => 442公里                    [6] => 134元                    [7] => 219元                    [8] => -                )            [7] => Array                (                    [0] => 8                    [1] => 南京南                    [2] => 10:22                    [3] => 10:24                    [4] => 2分                    [5] => 617公里                    [6] => 189元                    [7] => 304元                    [8] => -                )            [8] => Array                (                    [0] => 9                    [1] => 镇江南                    [2] => 10:44                    [3] => 10:46                    [4] => 2分                    [5] => 682公里                    [6] => 209元                    [7] => 334元                    [8] => -                )            [9] => Array                (                    [0] => 10                    [1] => 丹阳北                    [2] => 10:57                    [3] => 10:59                    [4] => 2分                    [5] => 714公里                    [6] => 219元                    [7] => 354元                    [8] => -                )            [10] => Array                (                    [0] => 11                    [1] => 常州北                    [2] => 11:12                    [3] => 11:14                    [4] => 2分                    [5] => 747公里                    [6] => 229元                    [7] => 369元                    [8] => -                )            [11] => Array                (                    [0] => 12                    [1] => 无锡东                    [2] => 11:32                    [3] => 11:43                    [4] => 11分                    [5] => 804公里                    [6] => 249元                    [7] => 399元                    [8] => -                )            [12] => Array                (                    [0] => 13                    [1] => 苏州北                    [2] => 11:54                    [3] => 11:56                    [4] => 2分                    [5] => 831公里                    [6] => 254元                    [7] => 409元                    [8] => -                )            [13] => Array                (                    [0] => 14                    [1] => 昆山南                    [2] => 12:08                    [3] => 12:10                    [4] => 2分                    [5] => 862公里                    [6] => 263.5元                    [7] => 423.5元                    [8] => -                )            [14] => Array                (                    [0] => 15                    [1] => 上海虹桥                    [2] => 12:27                    [3] => -                    [4] => -                    [5] => 912公里                    [6] => 278.5元                    [7] => 448.5元                    [8] => -                )        )    [title] => 区间里程:912公里  区间时间:5小时22分)

人气教程排行