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