MJExtension 空值判断
某些时候后台传过来的某个字段为空时,会出现崩溃,或者显示null。在model中添加如下代码可解决。
-
(id)mj_newValueFromOldValue:(id)oldValue property:(MJProperty *)property{
if ([NSString isEmpty:oldValue]) {// 以字符串类型为例
return @"";
}
return oldValue;
}1
2
3
4
5
http://blog.csdn.net/miao_em/article/details/50638035
http://www.cocoachina.com/ios/20161110/18036.html
https://www.jianshu.com/p/bea2bfed3f3f (id)mj_newValueFromOldValue:(id)oldValue property:(MJProperty *)property{
if ([NSString isEmpty:oldValue]) {// 以字符串类型为例
return @"";
}
return oldValue;
}
在需要判断空值的类目中添加如下方法:
+(BOOL)isEmpty:(NSString*)text{
if ([text isEqual:[NSNull null]]) {
return YES;
}
else if ([text isKindOfClass:[NSNull class]])
{
return YES;
}
else if (text == nil){
return YES;
}
return NO;
}