看起來,從Wunderground讀取'條件'JSON輸出與從「警報」中準備輸出非常不同。以下是我的代碼的簡化版本。如何使用PHP從Wunderground讀取ALERT的JSON輸出?
$json_stringalert = file_get_contents("http://api.wunderground.com/api/myKey/alerts/q/MO/Kansas_City.json");
$parsed_jsonalert = json_decode($json_stringalert);
$description = $parsed_jsonalert->{'alerts'}->{'description'};
echo "${description}
回顯爲空,並且沒有錯誤。 URL的輸出部分看起來像這樣;
{
"response": {
"version":"0.1",
"termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
"features": {
"alerts": 1
}
}
,"query_zone": "037",
"alerts": [
{
"type": "FIR",
"description": "Fire Weather Warning",
"date": "10:27 am CST on March 2, 2017",
"date_epoch": "1488472020",
"expires": "6:00 PM CST on March 02, 2017",
"expires_epoch": "1488499200",
"tz_short":"CST",
"tz_long":"America/Chicago",
"message": "\u000A...Red flag warning in effect until 6 PM CST this evening for\u000Abreezy northwest winds and low relative humidity values for fire \u000Aweather zones 020, 021, 025, 028, 029, 030, 037, 038, 043, 044, \u000A045, 053, 054, 057, 060, 102, 103, 104, and 105...\u000A\u000AThe National Weather Service in Kansas City/Pleasant Hill has\u000Aissued a red flag warning, which is in effect until 6 PM CST this\u000Aevening. \u000A\u000A* Affected area...fire weather zones 025, 057, 060, 102, 103, \u000A 104, and 105.Fire weather zones 020, 021, 028, 029, 030, 037, \u000A 038, 043, 044, 045, 053, and 054. \u000A\u000A* Wind...sustained northwest winds of 20 mph with higher gusts are\u000A expected this afternoon. \u000A\u000A* Humidity...relative humidity values will fall into the low to\u000A middle 20 percent range. \u000A\u000A* Impacts...any fires that develop will likely spread rapidly. \u000A Outdoor burning is not recommended.\u000A\u000APrecautionary/preparedness actions...\u000A\u000AA red flag warning means that critical fire weather conditions\u000Aare either occurring now, or will shortly. A combination of\u000Astrong winds, low relative humidity, and warm temperatures can\u000Acontribute to extreme fire behavior.\u000A\u000A\u000A\u000ACramer\u000A\u000A\u000A",
"phenomena": "FW",
"significance": "W", ...
and more below.
有人可以幫我寫代碼來使用'描述'和其他輸出嗎?
警報是一個數組,所以你必須爲每個訪問說明使用循環 – mickadoo