How do I make AFNetworking "responseObject" that I get an NSDictionary that I can parse?

I have this call with AFNetworking 1.0, which returns responseObjectwith the data from the API that I want:

[[AFDiffbotClient sharedClient] postPath:@"http://diffbot.com/api/batch" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {

However, I have no idea how to handle it responseObject.

If I check [responseObject class], I get NSData.

If I NSLog(@"%@", responseObject), I get a bunch of numbers (I assume that the memory addresses):

<5b0a7b22 68656164 65727322 3a5b7b22 6e616d65 223a6e75 6c6c2c22 76616c75 65223a22 48545450 2f312e31 20323030 204f4b22 7d2c7b22 6e616d65 223a2244 622652

If I do this:

NSString *responseString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"%@", responseString);

I get the result I want! But, this is a NSString.

If I do this:

NSError *error;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:responseObject options:kNilOptions error:&error];
NSLog(@"%@", responseDictionary);

NSDictionary, (..: , NSString).

?

+4
1

.

- (void) requestDataFinish:(NSData *)data withError:(NSError *)networkError
{
    NSDictionary *responseData;
    NSError *error = nil;
    if (data != nil) {
        responseData = [NSJSONSerialization JSONObjectWithData:data
                                                       options:NSJSONReadingMutableContainers
                                                         error:&error];
    }
...
+8

Source: https://habr.com/ru/post/1523398/


All Articles