AFNetworking 2.0 - 可变json

时间:2013-11-15 10:20:27

标签: ios objective-c json afnetworking afnetworking-2

我的代码目前看起来像这样

NSURL *URL = [NSURL URLWithString:URLForSend];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]
                                     initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
 {
     NSLog(@"%@", responseObject);
     [BoxJsonDataHelper gotNewJson:responseObject];
 } failure:^(AFHTTPRequestOperation *operation, NSError *error)
 {
     NSLog(@"Request Failure Because %@",[error userInfo]);
 }];

[operation start];

但是当尝试编辑接收到的对象中的字典时,我收到有关使用属于可变字典而不是字典的方法的错误。 如何让AFNetworking使用嵌套的可变对象?

1 个答案:

答案 0 :(得分:23)

告诉AFJSONResponseSerializer它需要返回可变容器:

operation.responseSerializer = 
  [AFJSONResponseSerializer serializerWithReadingOptions: NSJSONReadingMutableContainers]

所有文件都记录完备:http://cocoadocs.org/docsets/AFNetworking/2.0.0/