Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AFNetworking 2.0 - mutable 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];

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?

like image 787
Yoav Schwartz Avatar asked Nov 28 '22 15:11

Yoav Schwartz


1 Answers

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

operation.responseSerializer = 
  [AFJSONResponseSerializer serializerWithReadingOptions: NSJSONReadingMutableContainers]

It is all very well documented: http://cocoadocs.org/docsets/AFNetworking/2.0.0/

like image 98
rckoenes Avatar answered Dec 16 '22 00:12

rckoenes