我試圖通過提供JSON格式數(shù)據(jù)的Web服務(wù)請(qǐng)求天氣。我的PHP請(qǐng)求代碼沒有成功,是:$url="http://www.worldweatheronline.com/feed/weather.ashx?q=schruns,austria&format=json&num_of_days=5&key=8f2d1ea151085304102710";$json = file_get_contents($url);$data = json_decode($json, TRUE);echo $data[0]->weather->weatherIconUrl[0]->value; 這是返回的一些數(shù)據(jù)。為簡(jiǎn)潔起見,部分細(xì)節(jié)已被截?cái)?,但保留了?duì)象完整性:{ "data": { "current_condition": [ { "cloudcover": "31", ... } ], "request": [ { "query": "Schruns, Austria", "type": "City" } ], "weather": [ { "date": "2010-10-27", "precipMM": "0.0", "tempMaxC": "3", "tempMaxF": "38", "tempMinC": "-13", "tempMinF": "9", "weatherCode": "113", "weatherDesc": [ {"value": "Sunny" } ], "weatherIconUrl": [ {"value": "http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png" } ], "winddir16Point": "N", "winddirDegree": "356", "winddirection": "N", "windspeedKmph": "5", "windspeedMiles": "3" }, { "date": "2010-10-28", ... }, ... ] } }}
3 回答

紅顏莎娜
TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超13個(gè)贊
如果您使用以下代碼:
$json = file_get_contents($url);
$data = json_decode($json, TRUE);
TRUE返回一個(gè)數(shù)組而不是一個(gè)對(duì)象。
- 3 回答
- 0 關(guān)注
- 549 瀏覽
添加回答
舉報(bào)
0/150
提交
取消