关于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类型有关,如果返回的是字典或数组,就用第一项 
 
如有误,请指正。
上一篇:轻松学MVC4.0–1 建立MVC项目


下一篇:中小企业是否需要进行项目管理?