0

我在我的 iOS 应用程序上使用 Facebook 进行身份验证,并使用以下方法获取提要。当我检查它是否是有效的 JSON 对象时,它返回 true,但如果我尝试解析它,它会给我错误:

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

对此可以做些什么?这是来自服务器的内容,完全有效的 JSON - http://pastebin.com/ZwTnvi5g(通过 NSLog 得到结果)。

如何修复它以便 nsjsonserialization 正确解析它?

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

1 回答 1

1

实际上阅读文档可能会有所帮助。

 @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.

它自己解析一切,我什至不需要这样做。所以它返回有效的 NSDictionary 或 NSArray。

于 2013-07-30T20:05:56.997 回答