David Morin
David Morin

Reputation: 485

JSON not showing responnse

The following code will not work for me.

<?php
$json_string =    file_get_contents("http://api.wunderground.com/api/7ec5f6510a4656df/geolookup/forecast/q/40121    .json");
$parsed_json = json_decode($json_string);
$temp = $parsed_json->{'forecast'}->{'date'};
echo "Current date is ${temp}\n";


?>

It works when i put it like so:

$temp = $parsed_json->{'location'}->{'city'};

what am i missing here lol

Upvotes: 1

Views: 74

Answers (2)

Ruan Mendes
Ruan Mendes

Reputation: 92274

It look like you have extraneous spaces in your URL 40121 .json" Actually spaces at the end seem to be ignored

With spaces

No spaces

Upvotes: 0

Chuck Callebs
Chuck Callebs

Reputation: 16441

It should be:

$temp = $parsed_json->{'forecast'}->{'txt_forecast'}->{'date'};

For a better way of viewing JSON objects, look at this site.

Upvotes: 3

Related Questions