首页 > 其他 > 详细

【代码笔记】获得徐家汇的天气预报

时间:2016-07-06 10:21:01      阅读:248      评论:0      收藏:0      [点我收藏+]

一,代码。

技术分享
//获得徐家汇的天气预报
-(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℃

 

 

 
 

【代码笔记】获得徐家汇的天气预报

原文:http://www.cnblogs.com/yang-guang-girl/p/5645757.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!