百度地图天气接口api调用

RestTemplate restTemplate = new RestTemplate();
        Map<String,String> map = new HashMap<String,String>();
        map.put("district_id","这里填入的是你想要查询的城市或地区的六位数字地址码(简单说就是这个地区的身份证开头六位)");
        map.put("data_type","all");//这个是数据类型
        map.put("ak","这个填入的是你百度地图的访问AK");
        String res = restTemplate.getForObject(
                "https://api.map.baidu.com/weather/v1/?district_id={district_id}&data_type={data_type}&ak={ak}",
                String.class,
                map);
        JSONObject json = JSONObject.parseObject(res);//

下面是以南京栖霞区为例获得返回结果的数据格式如下:

{
	"status": 0,
	"result": {
		"location": {
			"country": "中国",
			"province": "江苏省",
			"city": "南京市",
			"name": "栖霞区",
			"id": "320113"
		},
		"now": {
			"text": "晴",
			"temp": 9,
			"feels_like": 8,
			"rh": 37,
			"wind_class": "2级",
			"wind_dir": "东南风",
			"uptime": "20211213162000"
		},
		"forecasts": [{
			"text_day": "晴",
			"text_night": "晴",
			"high": 10,
			"low": 1,
			"wc_day": "<3级",
			"wd_day": "东风",
			"wc_night": "<3级",
			"wd_night": "东南风",
			"date": "2021-12-13",
			"week": "星期一"
		}, {
			"text_day": "多云",
			"text_night": "多云",
			"high": 14,
			"low": 5,
			"wc_day": "<3级",
			"wd_day": "南风",
			"wc_night": "<3级",
			"wd_night": "东南风",
			"date": "2021-12-14",
			"week": "星期二"
		}, {
			"text_day": "多云",
			"text_night": "小雨",
			"high": 15,
			"low": 9,
			"wc_day": "<3级",
			"wd_day": "东北风",
			"wc_night": "3~4级",
			"wd_night": "东北风",
			"date": "2021-12-15",
			"week": "星期三"
		}, {
			"text_day": "小雨",
			"text_night": "小雨",
			"high": 11,
			"low": 4,
			"wc_day": "3~4级",
			"wd_day": "北风",
			"wc_night": "3~4级",
			"wd_night": "西北风",
			"date": "2021-12-16",
			"week": "星期四"
		}, {
			"text_day": "多云",
			"text_night": "多云",
			"high": 9,
			"low": -2,
			"wc_day": "4~5级",
			"wd_day": "北风",
			"wc_night": "<3级",
			"wd_night": "东北风",
			"date": "2021-12-17",
			"week": "星期五"
		}]
	},
	"message": "success"
}
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值