转载地址:http://blog.csdn.net/tarig/article/details/8204694
NSString* city = @"天津";
- NSStringEncoding chineseEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
- city = [city stringByAddingPercentEscapesUsingEncoding:chineseEncoding];
- NSString* str = [NSString stringWithFormat:@"http://php.weather.sina.com.cn/xml.php?city=%@&password=DJOYnieT8234jlsK&day=0",city];
新浪天气预报APIhttp://php.weather.sina.com.cn/xml.php?city=%B1%B1%BE%A9&password=DJOYnieT8234jlsK&day=0
其中,city后的城市转码。
Password固定
Day为0表示当天天气,1表示第二天的天气,2表示第三天的天气,以此类推,最大为4
返回的XML为
说明:
| 标签中1表示白天,2表示夜间 | |
| <status> < figure> <direction> <power> <temperature> <ssd> <ssd_l> <ssd_s> <tgd> <zwx> <zwx_l> <zwx_s> <ktk> <ktk_l> <ktk_s> <pollution> <pollution_l> <pollution_s> <xcz> <xcz_l> <xcz_s> <chy> <chy_l> <chy_shuoming> <gm> <gm_l> <gm_s> <yd> <yd_l> <yd_s> <zho> <zho_l> <zho_shuoming> <diy> <diy_l> <diy_shuoming> <fas> <fas_l> <fas_shuoming> <savedate_weather> <savedate_life> <savedate_zhishu> | 天气情况中文 天气情况拼音 风向 风级 温度 体感指数数值 体感度指数 体感度指数说明 体感温度 紫外线指数数值 紫外线指数 紫外线指数说明 空调指数数值 空调指数 空调指数说明 污染指数数值 污染物扩散条件 污染指数说明 洗车指数数值 洗车指数 洗车指数说明 穿衣指数数值 穿衣指数 穿衣说明 感冒指数数值 感冒指数 感冒指数说明 运动指数数值 运动指数 运动指数说明 天气预报日期 生活日期 指数日期 |
本文介绍了如何使用新浪天气预报API通过城市名称获取天气信息,并详细解释了API参数和返回的XML格式,包括城市转码、固定密码、天数选择及返回的天气指标解释。


被折叠的 条评论
为什么被折叠?



