加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

webservice 天气预报 Json格式

发布时间:2020-12-16 23:59:30 所属栏目:安全 来源:网络整理
导读:/** * 查询天气DEMO */public class Demo {private static HttpURLConnection conn;public static void main(String[] args){try {String urlStr = "http://m.weather.com.cn/data/101221502.html"; //101221502 可在这里查询:http://blog.csdn.net/zgyulon
/**
 * 查询天气DEMO
 */
public class Demo {

	private static HttpURLConnection conn;

	public static void main(String[] args){
			try {
				String urlStr = "http://m.weather.com.cn/data/101221502.html"; //101221502 可在这里查询:http://blog.csdn.net/zgyulongfei/article/details/7956118,也可以在<中国天气>官网上点击查看具体城镇,地址栏就有这个id
				URL url = new URL(urlStr);
				conn = (HttpURLConnection) url.openConnection();
				conn.setConnectTimeout(5000);
				System.out.println("连接中...");
				if(conn.getResponseCode()== 200){
					InputStream inputStream = null;
					ByteArrayOutputStream outputStream = null;
					try {
						System.out.println("进来了...");
						inputStream = conn.getInputStream();
						outputStream = new ByteArrayOutputStream();
						byte[] buffer = new byte[1024];
						int len = 0 ;
						while((len = inputStream.read(buffer)) != -1){
							outputStream.write(buffer,len);
							outputStream.flush();
						}
						
						System.out.println("数据:"+outputStream.toString("UTF-8"));
						
					} catch (IOException e) {
						System.out.println("数据读取出错...");
						e.printStackTrace();
					} finally{
						outputStream.close();
						inputStream.close();
					}
				}
			} catch (Exception e) {
				System.out.println("连接出错...");
				e.printStackTrace();
			} finally{
				conn.disconnect();
			}
			
	}

}


获取到的JSON:

{
    "weatherinfo": {
        "city": 霍邱
        "city_en": "huoqiu","date_y": "2013年11月20日","date": "","week": "星期三","fchh": "08",//系统更新时间
        "cityid": "101221501","temp1": "19℃~8℃",//今天温度
        "temp2": "15℃~7℃",//明天...
        "temp3": "17℃~9℃","temp4": "17℃~6℃","temp5": "10℃~4℃","temp6": "15℃~5℃","tempF1": "66.2℉~46.4℉","tempF2": "59℉~44.6℉","tempF3": "62.6℉~48.2℉","tempF4": "62.6℉~42.8℉","tempF5": "50℉~39.2℉","tempF6": "59℉~41℉","weather1": "多云",//今天天气
        "weather2": "多云",//明天..
        "weather3": "晴","weather4": "多云转小雨","weather5": "小雨转多云","weather6": "晴转多云","img1": "1",//天气描述(图片序号)
        "img2": "99","img3": "1","img4": "99","img5": "0","img6": "99","img7": "1","img8": "7","img9": "7","img10": "1","img11": "0","img12": "1","img_single": "1","img_title1": "多云",//天气描述(文字描述)
        "img_title2": "多云","img_title3": "多云","img_title4": "多云","img_title5": "晴","img_title6": "晴","img_title7": "多云","img_title8": "小雨","img_title9": "小雨","img_title10": "多云","img_title11": "晴","img_title12": "多云","img_title_single": "多云","wind1": "南风转东风小于3级",//风向描述
        "wind2": "东南风转东北风小于3级","wind3": "东南风转东北风小于3级","wind4": "西风3-4级","wind5": "西风4-5级转西北风小于3级","wind6": "西风转西北风3-4级","fx1": "南风","fx2": "东风","fl1": "小于3级",//风力描述
        "fl2": "小于3级","fl3": "小于3级","fl4": "3-4级","fl5": "4-5级转小于3级","fl6": "3-4级","index": "较冷",//今天穿衣指数
        "index_d": "建议着大衣、呢外套加毛衣、卫衣等服装。体弱者宜着厚外套、厚毛衣。因昼夜温差较大,注意增减衣服。","index48": "较冷",//48小时内穿衣指数
        "index48_d": "建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。","index_uv": "弱",//紫外线
        "index48_uv": "弱","index_xc": "适宜",//洗车
        "index_tr": "适宜",//旅游
        "index_co": "舒适",//人体舒适度
        "st1": "19","st2": "9","st3": "14","st4": "8","st5": "16","st6": "10","index_cl": "适宜",//晨练
        "index_ls": "适宜",//晾衣
        "index_ag": "极不易发"    //过敏
    }
}

当天基础天气接口
http://www.weather.com.cn/data/cityinfo/101010100.html

当天基础天气接口
http://www.weather.com.cn/data/sk/101010100.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读