I found some (most) of the following code on wunderground and it works. I can't figure out how to directly pull out specific information. Here's the code that will run as is:
$value)
{
if (is_object($value))
{
iterate("${name}->${key}", $value);
}
else if (is_array($value))
{
$n = count($value);
for ($i = 0; $i < $n; ++$i)
{
if (is_object($value[$i]))
{
iterate("${name}->${key}[$i]", $value[$i]);
}
else
{
print "${name}->${key}[$i] = '$value'\n";
echo "
";
}
}
}
else
{
print "${name}->${key} = '$value'\n";
echo "
";
print "${name}->${key} = '$value'\n";
print "$name->$key\n";
print_r ($value);
echo "
";
}
}
}
$api = 'http://api.wunderground.com/api';
$key = 'a66c7dca62f80c59'; //
$features = 'geolookup/forecast10day'; // your desired features here
$query = 'q/MA/KBOS'; // your query here
$data = json_decode(file_get_contents("$api/$key/$features/q/$query.json"));
iterate('data', $data);
Now's here the code that I added but is not working:
$test = $data->{'forecast'}->{'txt_forecast'}->{'forecastday[4]'}->{'fcttext'};
print "$test";
?>
I've decoded the json query into $data but how do I get at a specific piece of information?
$value)
{
if (is_object($value))
{
iterate("${name}->${key}", $value);
}
else if (is_array($value))
{
$n = count($value);
for ($i = 0; $i < $n; ++$i)
{
if (is_object($value[$i]))
{
iterate("${name}->${key}[$i]", $value[$i]);
}
else
{
print "${name}->${key}[$i] = '$value'\n";
echo "
";
}
}
}
else
{
print "${name}->${key} = '$value'\n";
echo "
";
print "${name}->${key} = '$value'\n";
print "$name->$key\n";
print_r ($value);
echo "
";
}
}
}
$api = 'http://api.wunderground.com/api';
$key = 'a66c7dca62f80c59'; //
$features = 'geolookup/forecast10day'; // your desired features here
$query = 'q/MA/KBOS'; // your query here
$data = json_decode(file_get_contents("$api/$key/$features/q/$query.json"));
iterate('data', $data);
Now's here the code that I added but is not working:
$test = $data->{'forecast'}->{'txt_forecast'}->{'forecastday[4]'}->{'fcttext'};
print "$test";
?>
I've decoded the json query into $data but how do I get at a specific piece of information?