使用YYModel
//修改后台传过来的字段名
+ (NSDictionary *)modelCustomPropertyMapper {
return @{@"recommendID":@"id"};
}
//数组中需要转换的模型类
+ (NSDictionary *)modelContainerPropertyGenericClass {
return @{@"teacherList":[MCourseTeacherListModel class],
@"assistantList":[MCourseTeacherListModel class]
};
}
使用MJExtension
/**
* 将属性名换为其他key去字典中取值
*
* @return 字典中的key是属性名,value是从字典中取值用的key
*/
+ (NSDictionary *)mj_replacedKeyFromPropertyName;
/**
* 数组中需要转换的模型类
*
* @return 字典中的key是数组属性名,value是数组中存放模型的Class(Class类型或者NSString类型)
*/
+ (NSDictionary *)mj_objectClassInArray;
模型中.m 示例
//修改后台传过来的字段名
+ (NSDictionary *)mj_replacedKeyFromPropertyName{
return @{@"idStr": @"id"};
}
网友评论