ObjectForKey always returning null or 0 when I kno

2019-08-05 06:59发布

问题:

I've made a call to retrieve a user's active permissions using

self.permissionRequest = [facebook requestWithGraphPath:@"me/permissions" andDelegate:self];

(I set the FBRequest object so I can identify it in the delegate method)

In the delegate I call:

        if (request == self.permissionRequest) {
        DLog(@"Result: %@", result);

    }

And I get a nice print out of active permissions:

Result: { data = ( { bookmarked = 1; "create_note" = 1; email = 1; installed = 1; "photo_upload" = 1; "publish_stream" = 1; "share_item" = 1; "status_update" = 1; "video_upload" = 1; } ); }

All well so far.

BUT I just want to determine if the "publish_stream" is on or off.

If I call

id *key = [result objectForKey:@"publish_stream"];
int keyInt = [key integerValue];
DLog(@"Key: %i", keyInt);

I always get 0.

If I call

NSString *key = [result objectForKey:@"publish_stream"];
    DLog(@"Key: %@", key);

I get 'null'.

What am I doing wrong?? Why can't I get the value of the publish_stream key? I've also tried using valueForKey: with the same results.

There must be a remarkably simple solution?

回答1:

I think your result dictionary has just one key, data, whose value is another dictionary, and everything else is inside that.

Try

[[result objectForKey:@"data"] objectForKey:@"publish_stream"];

You also have another error: you wrote

id *key

An id is already a pointer. You shouldn't put a * after it unless you want a double pointer.