Open Geetyty opened 3 years ago
A模型:-------------------------------------------------------- @interface AModel : NSObject
@property (nonatomic, retain) NSString name; @property (nonatomic, assign) NSUInteger age; @property (nonatomic, retain) NSArray<BModel > *list;
@end
@implementation AModel
B模型:-------------------------------------------------------- @interface BModel : NSObject
@property (nonatomic, retain) NSString *courseName; @property (nonatomic, assign) float score;
@implementation BModel
数据:--------------------------------------------------------- NSDictionary studentDic = @{ @"name" : @"XXXX", @"age" : @"29", @"list" : @[@{ @"courseName" : @"语文", @"score" : @"30" },@{ @"courseName" : @"数学", @"score" : @"100" },@{ @"courseName" : @"英语", @"score" : @"60" }] }; AModel student = [AModel modelWithJSON:studentDic];
期望与结果:-------------------------------------------------- 应该可以过滤掉不足50分的科目,但实际list中三个模型均生成了
源码观察:---------------------------------------------------- NSObject newOne = [cls new]; [newOne modelSetWithDictionary:one]; if (newOne) [objectArr addObject:newOne]; 上方源码导致全部解析,因为会必然添加模型,是否应该改为 NSObject newOne = [cls new]; if ([newOne modelSetWithDictionary:one]) [objectArr addObject:newOne];
A模型:-------------------------------------------------------- @interface AModel : NSObject
@property (nonatomic, retain) NSString name; @property (nonatomic, assign) NSUInteger age; @property (nonatomic, retain) NSArray<BModel > *list;
@end
@implementation AModel
@end
B模型:-------------------------------------------------------- @interface BModel : NSObject
@property (nonatomic, retain) NSString *courseName; @property (nonatomic, assign) float score;
@end
@implementation BModel
@end
数据:--------------------------------------------------------- NSDictionary studentDic = @{ @"name" : @"XXXX", @"age" : @"29", @"list" : @[@{ @"courseName" : @"语文", @"score" : @"30" },@{ @"courseName" : @"数学", @"score" : @"100" },@{ @"courseName" : @"英语", @"score" : @"60" }] }; AModel student = [AModel modelWithJSON:studentDic];
期望与结果:-------------------------------------------------- 应该可以过滤掉不足50分的科目,但实际list中三个模型均生成了
源码观察:---------------------------------------------------- NSObject newOne = [cls new]; [newOne modelSetWithDictionary:one]; if (newOne) [objectArr addObject:newOne]; 上方源码导致全部解析,因为会必然添加模型,是否应该改为 NSObject newOne = [cls new]; if ([newOne modelSetWithDictionary:one]) [objectArr addObject:newOne];