-2

wunderground.com の API キーを使用して、3 日間の天気予報を表示しています。モックアップのデザインには、日付、現在の状態 (曇り)、および各日の最高気温と最低気温が含まれます。現在の日付と気温を表示する方法を見つけましたが、次の 2 日間の天気を見つけようとして頭を悩ませています... 誰か助けてくれませんか?

var_dump($parsed_json)今日の天気 (日付、現在の気温、現在の状態など) だけを取得しています。

<?php 
$json_string = file_get_contents("api.wunderground.com/api/[key]/conditions/q/TN/…); 
$parsed_json = json_decode($json_string); 
$date = $parsed_json
                    ->{'current_observation'}
                    ->{'observation_time_rfc822'}; 
$temp_f = $parsed_json->{'current_observation'}->{'temp_f'}; 
$feels_like = $parsed_json->{'current_observation'}->{'feelslike_f'}; 
$weather = $parsed_json->{'current_observation'}->{'weather'}; 
echo "${date}\n"; 
echo "${temp_f}\n"; 
echo "Feels like... ${feels_like}\n"; 
echo "${weather}\n"; 
4

1 に答える 1

0

使用する必要があるWunderground API ドキュメントを参照してください。

http://api.wunderground.com/api/Your_Key/forecast/q/TN/XXX.json

あなたのfile_get_contents()

forecastこれは、週の予測をテキスト (txt_forecastオブジェクト) とデータのみのバージョン (simpleforecastオブジェクト)として持つオブジェクトを持つ応答を返します。

{  
   "response":{  
      ...
   },
   "forecast":{  
      "txt_forecast":{  
         "date":"2:00 PM PDT",
         "forecastday":[  
            {  
               "period":0,
               "icon":"partlycloudy",
               "icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
               "title":"Tuesday",
               "fcttext":"Partly cloudy in the morning, then clear. High of 68F. Breezy. Winds from the West at 10 to 25 mph.",
               "fcttext_metric":"Partly cloudy in the morning, then clear. High of 20C. Windy. Winds from the West at 20 to 35 km/h.",
               "pop":"0"
            },
            {  
               "period":1,
               "icon":"partlycloudy",
               "icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
               "title":"Tuesday Night",
               "fcttext":"Mostly cloudy. Fog overnight. Low of 50F. Winds from the WSW at 5 to 15 mph.",
               "fcttext_metric":"Mostly cloudy. Fog overnight. Low of 10C. Breezy. Winds from the WSW at 10 to 20 km/h.",
               "pop":"0"
            },
            {
             ...
            }
         ]
      },
      "simpleforecast":{  
         "forecastday":[  
            {  
               "date":{  
                  "epoch":"1340776800",
                  "pretty":"11:00 PM PDT on June 26, 2012",
                  "day":26,
                  "month":6,
                  "year":2012,
                  "yday":177,
                  "hour":23,
                  "min":"00",
                  "sec":0,
                  "isdst":"1",
                  "monthname":"June",
                  "weekday_short":"Tue",
                  "weekday":"Tuesday",
                  "ampm":"PM",
                  "tz_short":"PDT",
                  "tz_long":"America/Los_Angeles"
               },
               "period":1,
               "high":{  
                  "fahrenheit":"68",
                  "celsius":"20"
               },
               "low":{  
                  "fahrenheit":"50",
                  "celsius":"10"
               },
               "conditions":"Partly Cloudy",
               "icon":"partlycloudy",
               "icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
               "skyicon":"mostlysunny",
               "pop":0,
               "qpf_allday":{  
                  "in":0.00,
                  "mm":0.0
               },
               "qpf_day":{  
                  "in":0.00,
                  "mm":0.0
               },
               "qpf_night":{  
                  "in":0.00,
                  "mm":0.0
               },
               "snow_allday":{  
                  "in":0,
                  "cm":0
               },
               "snow_day":{  
                  "in":0,
                  "cm":0
               },
               "snow_night":{  
                  "in":0,
                  "cm":0
               },
               "maxwind":{  
                  "mph":21,
                  "kph":34,
                  "dir":"West",
                  "degrees":272
               },
               "avewind":{  
                  "mph":17,
                  "kph":27,
                  "dir":"West",
                  "degrees":272
               },
               "avehumidity":72,
               "maxhumidity":94,
               "minhumidity":58
            },
            {
             ...                
            }
         ]
      }
   }
}
于 2016-05-02T15:45:34.960 に答える