JSON解码不显示所有数据PHP

时间:2013-12-03 05:54:09

标签: php json

我正在尝试用PHP解码一个JSON文件(我一直这样做)。但是当我尝试使用这个文件时:https://www.hyzyne.co.nz/updatewlg/nzta.json。它解码它但后来只显示数组中JSON的最后一部分。

PHP:

$xml = file_get_contents('https://www.hyzyne.co.nz/updatewlg/nzta.json');

$data = json_decode($xml, true);

print_r($data);

如果您查看该文件,您会发现它很长。

当我打印以上内容时,我得到的是:

Array ( [data] => Array ( [0] => Array ( [roadevent] => Array ( [alternativeRoute] => Follow Detours [directLineDistance1] => 1.55 km southeast of Taradale [directLineDistance2] => 1.62 km southwest of Jervoistown [directLineDistance3] => 1.66 km east of Waiohiki [endDate] => 2013-12-03T18:25:18.677+13:00 [eventComments] => Now Clear [eventDescription] => Crash [eventId] => 84295 [eventIsland] => North Island [eventType] => Road Hazard [expectedResolution] => Until further notice [impact] => Caution [locationArea] => SH 50 Taradale [locations] => Array ( [location] => 050-0005/04.88 Taradale ) [planned] => false [startDate] => 2013-12-03T17:17:00.000+13:00 [status] => Resolved [wktGeometry] => SRID=27200;POINT (2841479.57385071 6176775.805777006) [eventCreated] => 2013-12-03T17:20:18.450+13:00 [eventModified] => 2013-12-03T18:25:18.380+13:00 [informationSource] => Police [supplier] => Official [eventRegions] => Array ( [eventRegion] => Taranaki, Manawatu-Wanganui, Hawke's Bay & Gisborne Region ) ) ) ) )

这不是所有的JSON,我自己制作了JSON文件。但我无法识别JSON中的任何问题。

即使把我的JSON放到http://jsonlint.com/,我也只能得到最后一段。有谁知道我做错了什么?

由于

2 个答案:

答案 0 :(得分:2)

你的json有问题。你正在重复属性“roadevent”。我假设所有不应该包含在数组{内的同一个对象[中。

{
"data": [{
    "roadevent": {
        "alternativeRoute": "Local Roads",
        "directLineDistance1": "1.43 km west of Heathcote Valley",
        "directLineDistance2": "1.45 km southwest of Ferrymead",
        "directLineDistance3": "1.68 km southwest of Mount Pleasant",
        "eventComments": "Bridges Not To Be Crossed By Any Overweight Loads Except For Iso Containers Being Moved On Existing Overweight Permits.   Any Other Overweight Loads (including Those Travelling On Area Permits) Will Be Considered On A Case By Case Basis.",
        "eventDescription": "Other",
        "eventId": "47078",
        "eventIsland": "South Island",
        "eventType": "Road Hazard",
        "expectedResolution": "Until further notice",
        "impact": "Vehicle Restrictions",
        "locationArea": "SH 74 Christchurch - Tunnel Rd, Horotane Valley Overpasses No 1 And 2 (bsn 217 & 218)",
        "locations": {
            "location": "074-0019/02.60-D   Heathcote Valley"
        },
        "planned": "false",
        "restrictions": "Road constricted for oversize and non-standard vehicles",
        "startDate": "2011-03-03T17:47:00.000+13:00",
        "status": "Active",
        "wktGeometry": "SRID=27200;POINT (2485362.087794318 5737151.779842964)",
        "eventCreated": "2011-03-03T17:49:29.260+13:00",
        "eventModified": "2012-08-15T17:52:54.210+12:00",
        "informationSource": "NMC",
        "supplier": "Official"
    },
    "roadevent": {
        "alternativeRoute": "-",
        "directLineDistance1": "0.69 km southwest of Hakataramea",
        "directLineDistance2": "0.92 km northeast of Kurow",
        "directLineDistance3": "6.43 km southeast of Lake Waitaki",
        "eventComments": "Speed Restriction In Place For Heavy Vehicles Of 20kph.",
        "eventDescription": "Other",
        "eventId": "62595",
        "eventIsland": "South Island",
        "eventType": "Road Hazard",
        "expectedResolution": "Until further notice",
        "impact": "Caution",
        "locationArea": "SH 82 Waitaki River Bridge No 1 ( Kurow Bridges)",
        "locations": {
            "location": "082-0053/16.68   -"
        },
        "planned": "false",
        "startDate": "2012-06-14T12:17:00.000+12:00",
        "status": "Active",
        "wktGeometry": "SRID=27200;POINT (2310306.0879597953 5605922.516155325)",
        "eventCreated": "2012-06-14T12:17:55.127+12:00",
        "eventModified": "2012-08-15T17:46:26.197+12:00",
        "informationSource": "NMC",
        "supplier": "Official"
    },

答案 1 :(得分:1)

  1. 只需将 ,"roadevent": 替换为 ,
  2. JSON结尾吉斯伯恩地区“}}]}}
  3. JSON开始 {“data”:{“roadevent”:[{“alternativeRoute”