Search code examples
iosobjective-cfacebook-graph-apifacebook-ios-sdk

NSJsonSerialzation not parsing results from Facebook - Cocoa error 3840


I'm authenticating with Facebook on my iOS application and use following method to grab the feed. When I check if it is valid JSON object, it returns true, but if I attempt to parse it, it gives me error:

Mistake: The operation couldn’t be completed. (Cocoa error 3840.)

What can be done about that? Here is what is arriving from server, perfectly valid JSON - http://pastebin.com/ZwTnvi5g (got it by NSLog the result).

How do I fix it so the nsjsonserialization parses it correctly?

- (void) refreshButtonPressed
{
    FBRequest *request = [[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:@"me/feed"];
    [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

        NSError *mistake;

        BOOL can = [NSJSONSerialization isValidJSONObject:result];

        NSLog(@"%d", can);


        NSDictionary *first = [NSJSONSerialization JSONObjectWithData:result options:NSJSONReadingAllowFragments error:&mistake];

        if (mistake) {
            NSLog(@"Mistake: %@", [mistake localizedDescription]);
        }
    }];
}

Solution

  • Actually reading documentation could have helped here.

     @param result          The result of the request.  This is a translation of
                            JSON data to `NSDictionary` and `NSArray` objects.  This
                            is nil if there was an error.
    

    It parses everything itself, I don't even need to do that. So it returns valid NSDictionary or NSArray.