-------------
1 气象局提供的接口:http://openweather.weather.com.cn/ 查看相关接口。
2 aqicn.org网站提供的数据:http://aqicn.org/publishingdata/json
---------------
可以通过访问 http://61.4.185.48:81/g/ 获取当前城市ID
或者访问http://m.weather.com.cn后 网页会自动定位当前城市 并在网址栏显示出相应的城市ID
以南京市(id:101190101)为例.
详细天气信息:http://m.weather.com.cn/atad/101190101.html
基本天气信息:http://www.weather.com.cn/data/cityinfo/101190101.html
各种天气指数:http://www.weather.com.cn/data/zs/101190101.html
风力方面信息:http://www.weather.com.cn/data/sk/101190101.html
以上各URL均可以直接访问而看到相应的JSON数据。
IOS提供的最基本的JSON解析方法:NSJSONSerialization。
// 请求
NSURLRequest *weatherReq = [NSURLRequest requestWithURL:[NSURL URLWithString:urlLink]];
NSData *weatherData = [NSURLConnection sendSynchronousRequest:weatherReq returningResponse:nil error:nil];
// 将NSData数据存储到NSDictionary
NSDictionary *weatherDict = [NSJSONSerialization JSONObjectWithData:weatherData options:NSJSONReadingMutableLeaves error:&error];
NSDictionary *weatherInfo = [weatherDict objectForKey:@"weatherinfo"];
当然如果需要提升性能,使用第三方的JSON解析方式例如JSONKit等。