开发中,时常碰到后端返回的json为空的情况,(null),<null>, 有NSString, NSNumber, NSDictionary, NSAarry,对象类型等等的数据类型,可能会不确定对象的具体类型,单单的判断一个,也会出现错的情况,所以把他们结合到一块
```
- (BOOL) isNullObject:(id)object
{
if (object == nil || [object isEqual:[NSNull class]]) {
return YES;
}else if ([object isKindOfClass:[NSNull class]])
{
if ([object isEqualToString:@""]) {
return YES;
}else
{
return NO;
}
}else if ([object isKindOfClass:[NSNumber class]])
{
if ([object isEqualToNumber:@0]) {
return YES;
}else
{
return NO;
}
}
return NO;
}
```
网友评论