Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 我使用if语句检查键是否为null,但我可以';我不明白出了什么问题_Objective C_Xcode10 - Fatal编程技术网

Objective c 我使用if语句检查键是否为null,但我可以';我不明白出了什么问题

Objective c 我使用if语句检查键是否为null,但我可以';我不明白出了什么问题,objective-c,xcode10,Objective C,Xcode10,在这里,我得到了通知列表null,它导致了一个异常。这是我的密码: if([[response.data valueForKey:@"NotificationList"] isEqual:@""] || [[response.data valueForKey:@"NotificationList"] isEqual:@"<null>"]) { NSLog(@"Data not available.!!!"); } else { NSLog(@"Data available

在这里,我得到了
通知
列表null,它导致了一个异常。这是我的密码:

if([[response.data valueForKey:@"NotificationList"] isEqual:@""] || [[response.data valueForKey:@"NotificationList"] isEqual:@"<null>"]) {

  NSLog(@"Data not available.!!!");

}
else
{
  NSLog(@"Data available.!!!");
}
if([[response.data-valueForKey:@“NotificationList”]isEqual:@”“][response.data-valueForKey:@“NotificationList”]isEqual:@”“){
NSLog(@“数据不可用!!!);
}
其他的
{
NSLog(@“数据可用!!!”);
}

您应该能够检查返回值的键

if(!response.data[@"NotificationList"]) {

  NSLog(@"Data not available.!!!");

}
else
{
    NSLog(@"Data available.!!!");
}

-有关更多详细信息,您只需检查返回值的键即可

if(!response.data[@"NotificationList"]) {

  NSLog(@"Data not available.!!!");

}
else
{
    NSLog(@"Data available.!!!");
}

-有关详细信息

当对象被打印或记录为
时,这并不意味着它是一个字符串对象,其内容为
。(嗯,这通常不是这个意思。)

相反,
NSNull的单例实例如何描述自己的

因此,正确的测试是:

id notificationList = [response.data valueForKey:@"NotificationList"];
if (!notificationList || [notificationList isKindOfClass:[NSNull class]])
    NSLog(@"Data not available.!!!");

当一个对象被打印或记录为
”时,这并不意味着它是一个字符串对象,其内容是
。(嗯,这通常不是这个意思。)

相反,
NSNull的单例实例如何描述自己的

因此,正确的测试是:

id notificationList = [response.data valueForKey:@"NotificationList"];
if (!notificationList || [notificationList isKindOfClass:[NSNull class]])
    NSLog(@"Data not available.!!!");

@Pratik Prajapati你能详细说明出了什么问题吗?为什么我不能让输出检查
响应。数据值forkey:@“NotificationList”]!=nil
并添加完整的源代码@Pratik Prajapati我试过,但没有从哪里得到
响应。数据
通知列表
NSNull.null
@Pratik Prajapati你能详细说明出了什么问题吗?为什么我没有得到检查
响应的输出。数据值forkey:@“通知列表”!=nil
并添加完整的源代码@Pratik Prajapati我试过了,但没有从哪里得到
响应。数据
通知列表
NSNull.null
。谢谢大家,它工作得很好。非常感谢@wilekithank大家,它工作得很好。非常感谢@Wileke