1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| @interface Bag : NSObject @property (copy, nonatomic) NSString *name; @property (assign, nonatomic) double price;@end@interface Student : NSObject @property (copy, nonatomic) NSString *ID; @property (copy, nonatomic) NSString *desc; @property (copy, nonatomic) NSString *nowName; @property (copy, nonatomic) NSString *oldName; @property (copy, nonatomic) NSString *nameChangedTime; @property (strong, nonatomic) Bag *bag; @end
@implementation Student
+ (NSDictionary *)replacedKeyFromPropertyName{ return @{ @"ID" : @"id", @"desc" : @"desciption", @"oldName" : @"name.oldName", @"nowName" : @"name.newName", @"nameChangedTime" : @"name.info.nameChangedTime", @"bag" : @"other.bag" }; }
@end
NSDictionary *dict = @{ @"id" : @"20", @"desciption" : @"孩子", @"name" : @{ @"newName" : @"lufy", @"oldName" : @"kitty", @"info" : @{ @"nameChangedTime" : @"2013-08" } }, @"other" : @{ @"bag" : @{ @"name" : @"小书包", @"price" : @100.7 } } };
Student *stu = [Student objectWithKeyValues:dict];
NSLog(@"ID=%@, desc=%@, oldName=%@, nowName=%@, nameChangedTime=%@", stu.ID, stu.desc, stu.oldName, stu.nowName, stu.nameChangedTime);
NSLog(@"bagName=%@, bagPrice=%f", stu.bag.name, stu.bag.price);
|