如何映射相同类型的嵌套对象?我有一个 xml,其中的对象可能包含多个相同类型的对象:
<entry location="l1">
<entry location="l1.1">
<entry location="l1.1.1">
</entry>
<entry location="l1.1.2">
</entry>
</entry>
</entry>
如果我添加具有相同映射的属性映射,我会得到无限递归:
+ (RKObjectMapping *)objectMapping {
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Entry class]];
[mapping addAttributeMappingsFromDictionary:@{@"location": @"location"}];
[mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"nextEntries"
toKeyPath:@"entries"
withMapping:[Entry objectMapping]]];
return mapping;
}
是否可以将子对象添加到每个父对象的数组中?
干杯
//编辑:以下代码对我有用:
+ (RKObjectMapping *)objectMapping
{
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Entry class]];
[mapping addAttributeMappingsFromDictionary:@{@"location": @"location"}];
RKObjectMapping *innerMapping = [RKObjectMapping mappingForClass:[Entry class]];
[innerMapping addAttributeMappingsFromDictionary:@{@"location": @"location"}];
[mapping addPropertyMapping:[RKRelationshipMapping
relationshipMappingFromKeyPath:@"entry"
toKeyPath:@"entries"
withMapping:innerMapping]];
return mapping;
}