在映射动态键时,我遇到了“找不到 keyPath 的对象映射:”的问题。
JSON响应是:
{
5471 = {
ImageCount = 0;
InventoryID = "3453dfdsfgt456t3";
MakeName = aaa;
ModelName = "a1";
StockNumber = 5471;
Year = 2012;
};
5516 = {
ImageCount = 0;
InventoryID = "fg456tgev65464b4v";
MakeName = bbb;
ModelName = b1;
StockNumber = 5516;
Year = 2002;
};
5567 = {
ImageCount = 0;
InventoryID = "fdg54646ghy67u65";
MakeName = ccc;
ModelName = c1;
StockNumber = 5567;
Year = 2008;
};
}
上面的keyPath值5567,5516,5471是随机值,怎么定义key呢?我的课程代码如下:
班级:
@interface CategoryPic : NSObject
@property(nonatomic,strong)NSString *imageCount_pic;
@property(nonatomic,strong)NSString *inventoryID_pic;
@property(nonatomic,strong)NSString *makeName_pic;
@property(nonatomic,strong)NSString *modelName_pic;
@property(nonatomic,strong)NSString *stockNumber_pic;
@property(nonatomic,strong)NSString *year_pic;
@end
- (void)viewDidLoad{
RKObjectMapping* new = [RKObjectMapping mappingForClass:[CategoryPic class]];
[new mapKeyOfNestedDictionaryToAttribute:@"stockid"];
[new mapKeyPath:@"(stockid).ImageCount" toAttribute:@"imageCount_pic"];
[new mapKeyPath:@"(stockid).InventoryID" toAttribute:@"inventoryID_pic"];
[new mapKeyPath:@"(stockid).MakeName" toAttribute:@"makeName_pic"];
[new mapKeyPath:@"(stockid).ModelName" toAttribute:@"modelName_pic"];
[new mapKeyPath:@"(stockid).StockNumber" toAttribute:@"stockNumber_pic"];
[new mapKeyPath:@"(stockid).Year" toAttribute:@"year_pic"];
[[NewSingelton class].objectManager.mappingProvider setMapping:new forKeyPath:@"stockid"];
}