我有以下数组
"forecast":{
"txt_forecast": {
"date":"11:00 PM EDT",
"forecastday": [
{
"period":0,
"icon":"partlycloudy",
"icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
"title":"Saturday",
"fcttext":"Partly cloudy in the morning, then mostly cloudy. High of 88F. Winds from the South at 5 to 10 mph.",
"fcttext_metric":"Partly cloudy in the morning, then mostly cloudy. High of 31C. Winds from the South at 10 to 15 km/h.",
"pop":"0"
}
,
{
"period":1,
"icon":"partlycloudy",
"icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
"title":"Saturday Night",
"fcttext":"Overcast in the evening, then partly cloudy. Low of 64F. Winds less than 5 mph.",
"fcttext_metric":"Overcast in the evening, then partly cloudy. Low of 18C. Winds less than 5 km/h.",
"pop":"10"
}
我将如何在 PHP 中显示信息?它一直持续到第 7 期。
编辑:这是我编辑的代码不起作用。
<?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'}->{'txt_forecast'}->{'date'};
$title = $parsed_json->{'forecast'}->{'txt_forecast'}->{'forecastday'}->{'title'};
$for = $parsed_json->{'forecast'}->{'txt_forecast'}->{'forecastday'}->{'fcttext'};
echo "Current date is ${temp}, ${title}: ${for}\n";
foreach($parsed_json['forecast']['forecastday[0]'] as $key => $value)
{
echo $value['period'];
echo $value['icon'];
// etc
}
?>