I'm sending the following message to an instance of AFHTTPClient. I expect the success block to be sent a Foundation object (a dictionary) but the debugger shows me that JSON is a _NSCFData object. This question on SO states that I need to set the Accept header to 'application/json'. Well, I'm doing that but AFNetworking still is not decoding the JSON in the response body. If I decode the json myself using NSJSONSerialization I get an NSDictionary as I expect. What am I doing wrong?
[client setDefaultHeader:@"Accept" value:@"application/json"];
[client postPath:@"/app/open_connection/"
parameters:params
success:^(AFHTTPRequestOperation *operation, id JSON) {
NSLog(@"successful login! %@", [JSON valueForKeyPath:@"status"]);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error opening connection");
NSAlert *alert = [NSAlert alertWithError:error];
[alert runModal];
}
];
Note: I'm programming the server in Python using Django. The content type of the response is 'application/json'