关于NSJSONReadingOptions参数的含义

  AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];  
    [operation start];  
      
    NSLog(@"request======%@",request);  
      
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)  
     {  
           
//         NSJSONReadingMutableContainers = (1UL << 0),  
//         NSJSONReadingMutableLeaves = (1UL << 1),  
//         NSJSONReadingAllowFragments = (1UL << 2)  
 
         NSData *data=(NSData *)responseObject;  
         NSError *error=nil;  
         NSDictionary *dicData1=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error ];  
         NSDictionary *dicData2=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error ];  
         NSDictionary *dicData3=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error ];  
 
         NSLog(@"解析成功 ===1=%@===2==%@====3==%@",dicData1,dicData2,dicData3);  
      
     } failure:^(AFHTTPRequestOperation *operation, NSError *error)  
     {  
               NSLog(@"解析失败  ====%@",error);  
     }];  
 
 
代码输出没有多大区别,我的英文不太好,看苹果官方文档上说,  
似乎是 第一个给数组或字典,第二选项为 可变字符,第三项为 不属于数组、字典。接收。  
 
NSJSONReadingMutableContainers  
Specifies that arrays and dictionaries are created as mutable objects.    //  创建可变的数组或字典 接收  
 
NSJSONReadingMutableLeaves  
Specifies that leaf strings in the JSON object graph are created as instances of NSMutableString.   // 指定在JSON对象可变字符串被创建为NSMutableString的实例  
 
NSJSONReadingAllowFragments  
Specifies that the parser should allow top-level objects that are not an instance of NSArray or NSDictionary   //  指定解析器应该允许不属于的NSArray或NSDictionary中的实例顶层对象  
 
可是我测试的 每一项都用字典接收,系统也没有给我报错。难道这是给返回的data类型有关,如果返回的是字典或数组,就用第一项  
 
如有误,请指正。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值