Reputation: 485
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
Reputation: 92274
It look like you have extraneous spaces in your URL Actually spaces at the end seem to be ignored40121 .json"
Upvotes: 0
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