码迷,mamicode.com
首页 > 其他好文 > 详细

获得徐家汇的天气预报

时间:2015-03-11 16:57:12      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

 

代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self getWeatherInfo];
    
}
//获得徐家汇的天气预报
-(void)getWeatherInfo{
    
    NSError *error;
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.weather.com.cn/data/101021200.html" ]];//代码为徐家汇
    
    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    
    NSDictionary *weatherDic = [NSJSONSerialization JSONObjectWithData:response  options:NSJSONReadingMutableLeaves error:&error];
    
    NSDictionary *weatherInfo = [weatherDic objectForKey:@"weatherinfo"];
    
    NSLog(@"天气%@",[NSString stringWithFormat:@"\n%@\n%@\n%@\n%@\n%@\n ", [weatherInfo objectForKey:@"city"],[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]]);
    
    /*
     天气
     徐家汇
     2014年3月4日
     星期二
     小雨转多云
     11℃~6℃
     */

}

 

输出:

2015-03-11 16:02:06.686 徐家汇天气预报[5526:214455] 天气

徐家汇

201434

星期二

小雨转多云

11~6

获得徐家汇的天气预报

标签:

原文地址:http://www.cnblogs.com/yang-guang-girl/p/4330175.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!