您的位置:首页 > 移动开发 > IOS开发

IOS解析JSON

2014-02-27 17:07 330 查看
- (void)viewDidLoad{[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.NSError *error;NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.weather.com.cn/data/101010100.html" ]];NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];NSDictionary *weatherDic = [NSJSONSerialization JSONObjectWithData:response  options:NSJSONReadingMutableLeaves error:&error];NSDictionary *weatherInfo = [weatherDic objectForKey:@"weatherinfo"];Weather.text = [NSString stringWithFormat:@"%@\n%@\n%@\n%@\n%@\n ", [weatherInfo objectForKey:@"city"],[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]]; ;NSLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );}
初学者最近自学IOS,今天试了一下json解析,从IOS5开始,APPLE提供了对json的原生支持(NSJSONSerialization)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: