相关的第三方类库大家可以去github上下载
具体代码如下 :
- (void)viewDidLoad { [super viewDidLoad]; NSData *data1=[NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"test" ofType:@"json"]]; //1.系统提供的json解析方法 NSLog(@"%@",data1); __autoreleasing NSError *err; NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data1 options:NSJSONReadingMutableLeaves error:&err]; NSLog(@"%@",dic[@"user"][@"location"]); NSLog(@"%@",dic); }
[super viewDidLoad]; NSString *path=[[NSBundle mainBundle]pathForResource:@"sina.json" ofType:nil]; NSData *data=[NSData dataWithContentsOfFile:path]; __autoreleasing NSError *err; NSDictionary *dic=[data objectFromJSONDataWithParseOptions:JKParseOptionNone error:&err]; NSLog(@"%@",dic[@"user"][@"location"]);
- (void)viewDidLoad { [super viewDidLoad]; NSString *path=[[NSBundle mainBundle]pathForResource:@"sina.json" ofType:nil]; NSData *data=[NSData dataWithContentsOfFile:path]; SBJsonParser *jsonParser=[[SBJsonParser alloc]init]; NSMutableDictionary *dic=[jsonParser objectWithData:data]; NSLog(@"%@",dic); }
- (void)viewDidLoad { [super viewDidLoad]; NSString *path=[[NSBundle mainBundle]pathForResource:@"sina" ofType:@"json"]; NSData *data=[NSData dataWithContentsOfFile:path]; NSDictionary *dic=[[CJSONDeserializer deserializer] deserialize:data error:nil]; NSLog(@"%@",dic); }