国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

天氣預(yù)報(bào)接口

2019-11-09 19:49:49
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.JSONObject;/** *  * @Description: TODO(使用中央天氣預(yù)報(bào)接口【非官方】調(diào)用天氣) * 城市編號(hào)參見(jiàn) http://blog.csdn.net/zhanbiane/article/details/54927340 * @author zhanbian  * @date 2017年2月9日 上午10:00:45 */public class Test {		public static void main(String[] args) {		getWeatherInfo();	}		//以上海為例	PRivate static void getWeatherInfo(){	  StringBuilder info = new StringBuilder();	  BufferedReader buff = null;	  	  URL url;	try {		url = new URL("http://weather.51wnl.com/weatherinfo/GetMoreWeather?cityCode=101020100&weatherType=0");		HttpURLConnection conn = (HttpURLConnection)url.openConnection();				conn.connect();		if(conn.getResponseCode()==HttpURLConnection.HTTP_OK){			buff = new BufferedReader(new InputStreamReader(conn.getInputStream(),"utf8"));			String str;			while((str = buff.readLine())!=null){				info.append(str);			}			JSONObject jsonObj = JSON.parSEObject(info.toString());			JSONObject weatherinfo = jsonObj.getJSONObject("weatherinfo");						//日期			String weatherDate = weatherinfo.getString("date_y");						//地點(diǎn)			String city = weatherinfo.getString("city");						//溫度			String temp1 = weatherinfo.getString("temp1");//今天			String temp2 = weatherinfo.getString("temp2");//明天						//天氣			String weather1 = weatherinfo.getString("weather1");//今天			String weather2 = weatherinfo.getString("weather2");//明天						//風(fēng)向			String wind1 = weatherinfo.getString("wind1");//今天			String wind2 = weatherinfo.getString("wind2");//明天						System.out.println("檢測(cè)時(shí)間:"+weatherDate+"/t城市"+city);			System.out.println("今天天氣狀況/t溫度:"+temp1+"/t天氣:"+weather1+"/t風(fēng)向:"+wind1);			System.out.println("明天天氣狀況/t溫度:"+temp2+"/t天氣:"+weather2+"/t風(fēng)向:"+wind2);		}	} catch (IOException e) {		e.printStackTrace();	}finally{		if(buff!=null){			try {				buff.close();			} catch (IOException e) {				e.printStackTrace();			}		}	}	}}

城市編號(hào)參見(jiàn):http://blog.csdn.net/zhanbiane/article/details/54927340

氣象局官方代言網(wǎng)站,智慧天氣:http://smart.weather.com.cn

要填寫(xiě)申請(qǐng)信息,審核通過(guò)才可,調(diào)用需要認(rèn)證參數(shù)。

下面提供幾個(gè)免費(fèi)的接口,(參考:http://www.android100.org/html/201507/24/167958.html)

中華萬(wàn)年歷:http://wthrcdn.etouch.cn/weather_mini?city=北京通過(guò)城市名字獲得天氣數(shù)據(jù),json數(shù)據(jù)http://wthrcdn.etouch.cn/weather_mini?citykey=101010100通過(guò)城市id獲得天氣數(shù)據(jù),json數(shù)據(jù)123.毒霸http://weather.123.duba.net/static/weather_info/101121301.html中央天氣預(yù)報(bào):http://weather.51wnl.com/weatherinfo/GetMoreWeather?cityCode=101040100&weatherType=0http://weather.51wnl.com/weatherinfo/GetMoreWeather?cityCode=101040100&weatherType=1別的地址:http://wthrcdn.etouch.cn/WeatherApi?citykey=101010100通過(guò)城市id獲得天氣數(shù)據(jù),xml文件數(shù)據(jù),當(dāng)錯(cuò)誤時(shí)會(huì)有<error>節(jié)點(diǎn)http://wthrcdn.etouch.cn/WeatherApi?city=北京通過(guò)城市名字獲得天氣數(shù)據(jù),xml文件數(shù)據(jù)


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 遂昌县| 惠来县| 会泽县| 江达县| 固镇县| 江门市| 闵行区| 锦屏县| 盖州市| 桦南县| 勃利县| 寻甸| 木里| 山阴县| 辛集市| 安吉县| 承德县| 清徐县| 湟中县| 叙永县| 法库县| 镇坪县| 如皋市| 宝兴县| 中西区| 镶黄旗| 房产| 曲靖市| 景泰县| 固镇县| 阿合奇县| 湘阴县| 宁国市| 云和县| 堆龙德庆县| 上思县| 横山县| 喀什市| 锡林浩特市| 建水县| 泸州市|