代码笔记获得徐家汇的天气预报
Posted 菜鸟and小白
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了代码笔记获得徐家汇的天气预报相关的知识,希望对你有一定的参考价值。
一,代码。
//获得徐家汇的天气预报
-(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℃
以上是关于代码笔记获得徐家汇的天气预报的主要内容,如果未能解决你的问题,请参考以下文章