ios - AFNetworking 2.0 - 可变 json

标签 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 改用嵌套的可变对象?

最佳答案

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

operation.responseSerializer = 
  [AFJSONResponseSerializer serializerWithReadingOptions: NSJSONReadingMutableContainers]

这一切都有很好的记录:http://cocoadocs.org/docsets/AFNetworking/2.0.0/

关于ios - AFNetworking 2.0 - 可变 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19998735/

相关文章:

iOS:outputStream 不会保持打开状态

ios - 使用 AWSS3GetBucketLocationRequest 获取存储桶区域

ios - swift 2 : NSData(contentsOfURL:url) returning nil

php - 如何从 PHP 调用和解码 JSON Web 服务?

javascript - 通过 Json 传输表单数据

ios - Swift - PageViewController 跳转到页面

ios - 在图像文件头上添加注释

ios - ViewModel 完成操作时在 ViewController 中的通知

ios - Objective C 从数组 [i] 中获取字典

ios - 在 map View 中心显示图钉