NSJsonSerialzation not parsing results from Facebook - Cocoa error 3840 [duplicate]

五迷三道 提交于 2019-12-25 18:40:35

问题


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]);
        }
    }];
}

回答1:


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.



来源:https://stackoverflow.com/questions/17956115/nsjsonserialzation-not-parsing-results-from-facebook-cocoa-error-3840

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!