我有一个如下所示的 JSON:
{
"key1":[
{
"desc":"key1decs.",
"duration":50;
},{
"desc":"",
"duration":90;
},{
"desc":"Kurz vor...",
"duration":30;
}
],
"key2":[
{
"desc":"key2decs.",
"duration":50;
},{
"desc":"blabla",
"duration":90;
}
]
}
我正在尝试进行映射。但是由于不同的未知/任意键,我被卡住了。我尝试在没有 KVC 的情况下进行映射,但它似乎不起作用。给我错误:keyPath 'key1.desc' 处的值转换失败。没有从 '__NSArrayI' 转换为 'NSString' 的策略。等等每个属性。我在网上看到没有 KVC 的映射不支持数组作为内部结构。请帮忙。什么是正确的方法?
编辑:实体:
@interface Sendung : NSObject
@property (nonatomic, strong) NSString *description;
@property (nonatomic, strong) NSNumber *duration;
@property (nonatomic, strong) NSNumber *sendungkey;
@end;
控制器:
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[Sendung class]];
mapping.forceCollectionMapping = YES;
[mapping mapKeyOfNestedDictionaryToAttribute:@"sendungkey"];
[mapping mapKeyPath:@"(sendungkey).desc" toAttribute:@"description"];
[mapping mapKeyPath:@"(sendungkey).duration" toAttribute:@"duration"];
[[RKObjectManager sharedManager].mappingProvider addObjectMapping:mapping ];
mapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[Sendung class] ];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:url objectMapping:mapping delegate:self];
这是我在 NSlogin 结果时得到的: ( (null), (null), (null), (null), (null) )