hynick
hynick

Reputation: 785

JSON Decode not showing all data PHP

I am trying to decode a JSON file in PHP (which I do all the time). But when I try and use this file: https://www.hyzyne.co.nz/updatewlg/nzta.json . It decodes it but then only shows the last part of the JSON in the array.

PHP:

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

$data = json_decode($xml, true);

print_r($data);

If you view the file you will see it is quite long.

When I print the above all I get is:

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

Which is not all of the JSON, I did make the JSON file myself. But I am unable to recognise any problems in the JSON.

Even when putting my JSON through http://jsonlint.com/ I only get the last segment. Does anyone know what I am doing wrong?

Thanks

Upvotes: 2

Views: 131

Answers (2)

Allen Chak
Allen Chak

Reputation: 1960

  1. just replace ,"roadevent": to ,
  2. JSON ending Gisborne Region"}}]}}
  3. JSON starting {"data":{"roadevent":[{"alternativeRoute"

Upvotes: 1

JRomero
JRomero

Reputation: 4868

You have an issue with your json. You are repeating the property "roadevent". I'm assuming they all shouldn't be contained in the same object { inside the array [.

{
"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"
    },

Upvotes: 2

Related Questions