使用replacedKeyFromPropertyName
使用方法:
1.在模型類(lèi).m文件引入"MJExtension.h"
2.實(shí)現(xiàn)方法
- (NSDictionary *)replacedKeyFromPropertyName
{
return @{@“非關(guān)鍵字的屬性名” : @“數(shù)組的key”};
}
-(NSDictionrary *)objectClassInArray
{
return @{@"對(duì)應(yīng)字段key" : [類(lèi)2 class]};
}
mj_objectArrayWithKeyValuesArray:
(id)mj_newValueFromOldValue:(id)oldValue property:(MJProperty *)property{
if ([NSString isEmpty:oldValue]) {// 以字符串類(lèi)型為例
return @"";
}
return oldValue;
}
在需要判斷空值的類(lèi)目中添加如下方法:
+(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;
}