ObjectForKey always returning null or 0 when I know the value to be 1

时光毁灭记忆、已成空白 提交于 2020-01-05 08:51:17

问题


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.



来源:https://stackoverflow.com/questions/9532962/objectforkey-always-returning-null-or-0-when-i-know-the-value-to-be-1

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