【问题标题】:AFNetworking 2.0 - mutable jsonAFNetworking 2.0 - 可变 json
【发布时间】:2013-11-28 16:59:16
【问题描述】:

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

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

【问题讨论】:

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


【解决方案1】:

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

operation.responseSerializer = 
  [AFJSONResponseSerializer serializerWithReadingOptions: NSJSONReadingMutableContainers]

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

【讨论】:

  • 谢谢,我从文档中理解错了,它应该是默认设置。
  • 顺便说一句,此选项优化了位内存处理,因为它不会将可变容器复制到不可变容器中。并返回可变叶子: manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions: NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves];
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多