NSJsonSerialzation无法解析来自Facebook的结果-可可错误3840 [英] NSJsonSerialzation not parsing results from Facebook - Cocoa error 3840

查看:49
本文介绍了NSJsonSerialzation无法解析来自Facebook的结果-可可错误3840的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

对此可以采取什么措施?这是从服务器传来的内容,完全有效的JSON- http://pastebin.com/ZwTnvi5g (由NSLog结果).

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

如何解决它,以便nsjsonserialization正确解析它?

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

推荐答案

实际上,阅读文档可以在这里有所帮助.

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.

它本身解析所有内容,我什至不需要这样做.因此它将返回有效的NSDictionary或NSArray.

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

这篇关于NSJsonSerialzation无法解析来自Facebook的结果-可可错误3840的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆