当我知道值为1时,ObjectForKey总是返回null或0 [英] ObjectForKey always returning null or 0 when I know the value to be 1
问题描述
我已致电
self.permissionRequest = [facebook requestWithGraphPath:@"me/permissions" andDelegate:self];
(我设置了FBRequest对象,以便可以在委托方法中标识它)
(I set the FBRequest object so I can identify it in the delegate method)
我在代表中打电话给
if (request == self.permissionRequest) {
DLog(@"Result: %@", result);
}
从活动权限中我可以得到很好的打印结果:
And I get a nice print out of active permissions:
结果:{ 数据=( { 已加书签= 1; "create_note" = 1; 电子邮件= 1; 已安装= 1; "photo_upload" = 1; "publish_stream" = 1; "share_item" = 1; "status_update" = 1; "video_upload" = 1; } ); }
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.
但是我只想确定"publish_stream"是打开还是关闭.
BUT I just want to determine if the "publish_stream" is on or off.
如果我打电话
id *key = [result objectForKey:@"publish_stream"];
int keyInt = [key integerValue];
DLog(@"Key: %i", keyInt);
我总是得到0.
如果我打电话
NSString *key = [result objectForKey:@"publish_stream"];
DLog(@"Key: %@", key);
我得到"null".
I get 'null'.
我做错了什么?为什么无法获取publish_stream键的值?我也尝试过使用valueForKey:具有相同的结果.
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?
推荐答案
我认为您的结果字典只有一个键data
,其值是另一本字典,而其他所有内容都在其中.
I think your result dictionary has just one key, data
, whose value is another dictionary, and everything else is inside that.
尝试
[[result objectForKey:@"data"] objectForKey:@"publish_stream"];
您还有另一个错误:您写了
You also have another error: you wrote
id *key
id
已经是一个指针.除非您要使用双指针,否则不应在其后放置*
.
An id
is already a pointer. You shouldn't put a *
after it unless you want a double pointer.
这篇关于当我知道值为1时,ObjectForKey总是返回null或0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!