我正在尝试使用 RestKit 映射一些 JSON 数据,但到目前为止一直无法正确完成。数据是一组分层的天数和注册。它看起来如下(我不可能更改它):
{
"days":
{
"2012-10-29": {
"2106303": {
"activityCode": "LU",
"approved": false,
"hours": 0.5,
"description": "some description",
},
"2106304": {
"activityCode": "VF",
"approved": false,
"hours": 7.5,
"description": "some other description",
}
},
"2012-10-30": null,
}
}
我的代码如下所示:
- (void)setupWeekMappingForManager:(RKObjectManager *)manager
{
RKObjectMapping *registrationMapping = [RKObjectMapping mappingForClass:[Registration class]];
registrationMapping.forceCollectionMapping = YES;
[registrationMapping mapKeyOfNestedDictionaryToAttribute:@"registrationNumber"];
RKObjectMapping *dayMapping = [RKObjectMapping mappingForClass:[Day class]];
dayMapping.forceCollectionMapping = YES;
[dayMapping mapKeyOfNestedDictionaryToAttribute:@"date"];
// how can this relationship be mapped?
[dayMapping mapKeyPath:@"(date)." toRelationship:@"registrations" withMapping:registrationMapping];
[manager.mappingProvider setMapping:dayMapping forKeyPath:@"days"];
}
它愉快地返回了日子,但我找不到映射两种类型之间关系的好方法,
任何朝着正确方向的推动将不胜感激,
最好的问候,汤米