作者:笑楔信 来自简书 来自作者有道云笔记 有道地址
一:小米天气预报接口:
优点:内容很多,当天的数据包含PM2.5、各种指数都有
问题:明天到到周日的数据也有个参数,但不知道如何取。不知道是不是涉及侵权
二:聚合数据:(免费版)
请求地址:http://v.juhe.cn/weather/index
请求参数:cityname=%E5%A4%AA%E5%8E%9F&dtype=&format=&key=9c44df781a01d4f579aa8c782a578ea5
请求方式:GET
貌似单日请求次数最多500个,而且好像是所有用这个appkey的客户端,没试过。
三:中国天气网
实时天气接口:http://www.weather.com.cn/data/sk/101010100.html
{"weatherinfo":{"city":"北京","cityid":"101010100","temp":"6","WD":"西风","WS":"3级","SD":"27%","WSE":"3","time":"11:05","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB","njd":"暂无实况","qy":"1017","rain":"0"}}
优点:简单,SD:湿度吧
缺点:数据太少,而且看不懂英文代表啥
城市天气信息:http://www.weather.com.cn/data/cityinfo/101010100.html
{"weatherinfo":{"city":"北京","cityid":"101010100","temp1":"9℃","temp2":"-2℃","weather":"晴","img1":"d0.gif","img2":"n0.gif","ptime":"11:00"}}
内容:包含了天气,温度区间,http://m.weather.com.cn/img/天气图片白天和夜间gif,更新时间
城市六天预报:http://m.weather.com.cn/data/101110101.html
缺点:不能用了
四:K780
http://api.k780.com:88/?app=weather.today&weaid=1&&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json
具体说明网址:http://www.k780.com/api/weather.today
优点:貌似挺全的,而且有说明,似乎能用,就是不知道有啥限制
五:随身云
简化版:(返回JSON)http://wthrcdn.etouch.cn/weather_mini?citykey=101010100
详细版:(返回XML)http://wthrcdn.etouch.cn/WeatherApi?citykey=101010100
六:百度
请求地址:http://apistore.baidu.com/microservice/weather?cityname=北京
api:http://apistore.baidu.com/astore/serviceinfo/1798.html
七:取得百度天气接口写法
-(void)getWeatherInf {
// 1.获得请求管理者
AFHTTPRequestOperationManager*mgr = [AFHTTPRequestOperationManagermanager];
// 2.封装请求参数
NSMutableDictionary*params = [NSMutableDictionarydictionary];
NSString*url =@"http://apistore.baidu.com/microservice/weather";
params[@"cityname"] =@"太原";
// 3.发送GET请求
[mgrGET:urlparameters:params
success:^(AFHTTPRequestOperation*operation,idresponseObject) {
NSLog(@"%@",responseObject);
self.weatherInf= [[NSMutableDictionaryalloc]init];
self.weatherInf= [responseObjectvalueForKey:@"retData"];
self.weatherLab.text= [self.weatherInfvalueForKey:@"weather"];
self.wendulab.text= [NSStringstringWithFormat:@"%@°/%@°",[self.weatherInfvalueForKey:@"h_tmp"],[self.weatherInfvalueForKey:@"l_tmp"]];
self.weatherImg.image= [UIImageimageNamed:[self.weatherAndCodevalueForKey:[self.weatherInfvalueForKey:@"weather"]]];
}failure:^(AFHTTPRequestOperation*operation,NSError*error) {
NSLog(@"%@",error);
}];
}
附一些参数:
self.cityAndCode= [[NSMutableDictionaryalloc]initWithObjectsAndKeys:@"101100101",@"太原",@"101100201",@"大同",@"101100901",@"朔州",@"101101001",@"忻州",@"101101100",@"吕梁",@"101100301",@"阳泉",@"101100401",@"晋中",@"101100701",@"临汾",@"101100501",@"长治",@"101100601",@"晋城",@"101100801",@"运城",nil];
self.weatherAndCode= [[NSMutableDictionaryalloc]initWithObjectsAndKeys:@"0.gif",@"晴",@"1.gif",@"多云",@"2.gif",@"阴",@"3.gif",@"阵雨",@"4.gif",@"雷阵雨",@"5.gif",@"雷阵雨伴有冰雹",@"6.gif",@"雨夹雪",@"7.gif",@"小雨",@"8.gif",@"中雨",@"9.gif",@"大雨",@"10.gif",@"暴雨",@"11.gif",@"大暴雨",@"12.gif",@"特大暴雨",@"13.gif",@"阵雪",@"14.gif",@"小雪",@"15.gif",@"中雪",@"16.gif",@"大雪",@"17.gif",@"暴雪",@"18.gif",@"雾",@"19.gif",@"冻雨",@"20.gif",@"沙尘暴",@"21.gif",@"小到中雨",@"22.gif",@"中到大雨",@"23.gif",@"大到暴雨",@"24.gif",@"暴雨到大暴雨",@"25.gif",@"大暴雨到特大暴雨",@"26.gif",@"小到中雪",@"27.gif",@"中到大雪",@"28.gif",@"大到暴雪",@"29.gif",@"浮尘",@"30.gif",@"扬沙",@"31.gif",@"强沙尘暴",@"32.gif",@"霾",nil];
附本人的引用:
#import"XHHttpClient.h"
#import"AFNetworking.h"
#import"UIImageView+WebCache.h"
网友评论