Question

I'm trying to get data from Facebook, but I'm getting this error when I try to parse the data to a Dictionary:

Mistake: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (No value.) UserInfo=0x144ad420 

This is my code:

NSString *query =
 @"SELECT page_id, type FROM page_fan WHERE uid = me() ";
 // Set up the query parameter
 NSDictionary *queryParam = @{ @"q": query };
 // Make the API request that uses FQL
 [FBRequestConnection startWithGraphPath:@"/fql"
 parameters:queryParam
 HTTPMethod:@"GET"
 completionHandler:^(FBRequestConnection *connection,
 id results,
 NSError *error) {
 if (error) {
 NSLog(@"Error: %@", [error localizedDescription]);
 } else {


 BOOL can = [NSJSONSerialization isValidJSONObject:results];
 NSLog(@"can %d", can);

 NSError *mistake;
 NSDictionary *first = [NSJSONSerialization JSONObjectWithData:results options:0 error:&mistake];


 if (mistake) {
 NSLog(@"Mistake: %@", mistake);
 } else {
 NSLog(@"No mistake");
 }

the can identifier returns '1' so I'm assuming the error is not with the data that Facebook is providing.

The data from Facebook is returning fine, this is a sample of results:

data =     (
                {
            "page_id" = 253370381511811;
            type = "PUBLIC FIGURE";
        },
                {
            "page_id" = 148389618201;
            type = "LOCAL BUSINESS";
        },
                {
            "page_id" = 213631462169238;
            type = COMMUNITY;
        }
Was it helpful?

Solution

I don't know that library, but the code that you wrote cannot possibly work.

isValidJSONObject is a method that checks whether you have an object that can be serialised to JSON, that is an NSArray or NSDictionary containing only keys and values that can be serialised to JSON.

JSONObjectWithData is a method that takes an NSData object and deserialises it to an NSArray or NSDictionary.

Since an NSData object will always fail in isValidJSONObject, and an NSDictionary or NSArray is never valid input for JSONObjectWithData, one of these calls must fail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top