从JSON接收数据,如下所示:

{
    myself = 1;
    "id" = 123;
}

并将其放入NSDictionary * messageDic中,我还定义了一个值* isMyself以接收自己的值(value)
Boolean isMyself = [messageDic objectForKey:@"myself"];

但它不起作用。

所以我打印日期类型
const char* className = class_getName([[messageDic objectForKey:@"myself"] class]);
NSLog(@"yourObject is a: %s", className);
NSLog(@"Size of BOOL %d", sizeof(isMyself));
NSLog(@"Size of BOOL %@", [messageDic objectForKey:@"myself"]);

结果是:
2012-08-01 17:41:48.886  yourObject is a: __NSCFBoolean
2012-08-01 17:41:48.887  Size of BOOL 1
2012-08-01 17:41:48.887  Size of BOOL 0

并且下面的if部分也不起作用。
if ([messageDic objectForKey:@"myself"] == 0)

我试过了
NSCFBoolean *isMyself = [messageDic objectForKey:@"myself"];

我上面有错误表格。

我的问题是我应该如何测试[messageDic objectForKey:@"myself"]的值?什么是__NSCFBoolean

谢谢!

最佳答案

您从[messageDic objectForKey:@“myself”]中获得的结果(即NSNumber),然后需要将结果转换为Bool。因此,请尝试以下操作:

if ([[messageDic objectForKey:@"myself"]boolValue] == NO)

10-04 21:14