webservice 天气预报 Json格式

/**
 * 查询天气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, 0, 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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值