AFNetworking 2.0 - 可变json [英] AFNetworking 2.0 - mutable json

查看:131
本文介绍了AFNetworking 2.0 - 可变json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My code currently looks like this

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

But when trying to edit dictionaries in object received, I get an error about using methods that belongs to a mutable dictionary rather than a dictionary. How do I make AFNetworking use nested mutable objects instead?

推荐答案

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

You tell the AFJSONResponseSerializer that it needs to return mutable containers:

operation.responseSerializer = 
  [AFJSONResponseSerializer serializerWithReadingOptions: NSJSONReadingMutableContainers]

记录非常清楚: http://cocoadocs.org/docsets/AFNetworking/2.0.0/

这篇关于AFNetworking 2.0 - 可变json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆