星空网 > 软件开发 > 操作系统

iOS json解析的几种方法 NSJSONSerialization,JSONKit,SBJson ,TouchJson

相关的第三方类库大家可以去github上下载

1.NSJSONSerialization

具体代码如下 :

- (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);}

 2.JSONKit 这是需要导入第三方类库

 [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"]);

 

3.SBJson 同样需要导入第三方类库

- (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);  }

 4.TouchJson 第三方类库

- (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);  }

 




原标题:iOS json解析的几种方法 NSJSONSerialization,JSONKit,SBJson ,TouchJson

关键词:JS

JS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

中非桥电商供应链:https://www.goluckyvip.com/tag/49088.html
中港物流专线:https://www.goluckyvip.com/tag/49089.html
中港专线:https://www.goluckyvip.com/tag/49090.html
中港专线货运:https://www.goluckyvip.com/tag/49091.html
中国 杭州 跨境电子商务综合试验区:https://www.goluckyvip.com/tag/49092.html
中国 厦门 跨境电商大会:https://www.goluckyvip.com/tag/49093.html
七月份适合去日本旅游吗 7月份去日本哪里好玩:https://www.vstour.cn/a/363192.html
凤岗汽车站到松山湖风景区 松岗汽车站到凤凰山怎么坐车:https://www.vstour.cn/a/363193.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流