AFNetworking + JSONKit + iOS 5.0+ = JSON parsing does not work (returns nil objects when trying to parse).
AFNetworking + iOS 5.0+ = JSON parsing works fine.
AFNetworking + JSONKit + iOS 4.X = JSON Parsing works
AFNetworking + iOS 4.X = JSON Parsing doesn't work (because NSJSONSerializer is only available for iOS5.0+).
How do I solve this problem? Snippet of code:
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
if([sender respondsToSelector:finish])
{
NSArray *responseArray = JSON;
[sender performSelector:finish withObject:JSON];
}
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Error retrieving: %@\n%@", error, response);
if([sender respondsToSelector:fail])
{
[sender performSelector:fail];
}
}];
Strange that JSONKit isn't working with iOS 5... Nonetheless, there is a simple way to override JSONKit for JSON encode / decode, and first try NSJSONSerialization, if that's available. Simply add
#define _AFNETWORKING_PREFER_NSJSONSERIALIZATION_
to a header file in the project (Prefix.pch
, perhaps), and you should be all set.