https://github.com/CoderMJLee/MJExtension?tab=readme-ov-file#-model-name---json-key-mapping%E6%A8%A1%E5%9E%8B%E4%B8%AD%E7%9A%84%E5%B1%9E%E6%80%A7%E5%90%8D%E5%92%8C%E5%AD%97%E5%85%B8%E4%B8%AD%E7%9A%84key%E4%B8%8D%E7%9B%B8%E5%90%8C%E6%88%96%E8%80%85%E9%9C%80%E8%A6%81%E5%A4%9A%E7%BA%A7%E6%98%A0%E5%B0%84```
@
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/***********************************************/
// How to map
[Student mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
return @{
@"ID" : @"id",
@"desc" : @"description",
@"oldName" : @"name.oldName",
@"nowName" : @"name.newName",
@"nameChangedTime" : @"
name.info[1].nameChangedTime",
@"bag" : @"other.bag"
};
}];
// Equals: Student.m implements +mj_replacedKeyFromPropertyName method.
NSDictionary *dict = @{
@"id" : @"20",
@"description" : @"kids",
@"name" : @{
@"newName" : @"lufy",
@"oldName" : @"kitty",
@"info" : @[
@"test-data",
@{
@"nameChangedTime" : @"2013-08"
}
]
},
@"other" : @{
@"bag" : @{
@"name" : @"a red bag",
@"price" : @
100.7
}
}
};
// JSON -> Student
Student *stu = [Student mj_objectWithKeyValues:dict];
// Printing
NSLog(@"ID=%@, desc=%@, oldName=%@, nowName=%@, nameChangedTime=%@",
stu.ID, stu.desc, stu.oldName, stu.nowName, stu.nameChangedTime);
// ID=20, desc=kids, oldName=kitty, nowName=lufy, nameChangedTime=2013-08
NSLog(@"bagName=%@, bagPrice=%f",
stu.bag.name, stu.bag.price);
// bagName=a red bag, bagPrice=100.700000
```
I guess 他在找这个?