IOS SBJson解析Json文件

最近在搞到,如何解析json文件,使用ios自带的函数很容易解析出来,但是对于中文的问题,一直困扰着我,于是查看了各种相关资料,最后我的解决方法如下:

1,让我找到了一个兼容ARC机制的类库,SBJson,现在地址:https://github.com/stig/json-framework/downloads,最近的一个版本支持ARC

2,将其下载过来后,引入到项目中,#import "SBJson.h"

3,使用方法是


NSURL *url = [NSURL URLWithString:@"http://m.weather.com.cn/data/101180701.html"];

NSError *error = nil;

NSString *jsonString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];

SBJsonParser *parser = [[SBJsonParser alloc] init];

NSDictionary *rootDic = [parser objectWithString:jsonString error:&error];

NSDictionary *weatherInfo = [rootDic objectForKey:@"weatherinfo"];

txtView.text = [NSString stringWithFormat:@"今天是 %@  %@  %@  的天气状况是:%@  %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectF

你可能感兴趣的:(IOS SBJson解析Json文件)