Ios 同一对象上字符串和键路径值的RestKit映射数组

Ios 同一对象上字符串和键路径值的RestKit映射数组,ios,objective-c,restkit,restkit-0.20,Ios,Objective C,Restkit,Restkit 0.20,我已经找了几个小时的答案了,我不知道该怎么办 我有一个需要映射的JSON,它有一个没有keyPath的字符串数组,但也有一个需要映射的属性,该属性有一个keyPath。我使用的是RestKit0.21.0,当我更新到RestKit0.22.0时出现了相同的错误 JSON: RKResponseDescriptor: RKEntityMapping *moduleMapping = [RKEntityMapping mappingForEntityForName:@"Module" inManag

我已经找了几个小时的答案了,我不知道该怎么办

我有一个需要映射的JSON,它有一个没有keyPath的字符串数组,但也有一个需要映射的属性,该属性有一个keyPath。我使用的是RestKit0.21.0,当我更新到RestKit0.22.0时出现了相同的错误

JSON:

RKResponseDescriptor:

RKEntityMapping *moduleMapping = [RKEntityMapping mappingForEntityForName:@"Module" inManagedObjectStore:store];
    [moduleMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"type"]];
    [moduleMapping addAttributeMappingsFromDictionary:@{@"@parent.site" : @"site"}];

    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:moduleMapping method:RKRequestMethodAny pathPattern:nil keyPath:@"content.modulos" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
当我运行此命令时,它成功地将数组映射到3个不同的元素中,如您所见:

SUCCESS (
    "<Module: 0x8e54280> (entity: Module; id: 0x8cd31f0 <x-coredata://B31664A2-091E-43B8-9B36-EB7AF6C27292/Module/p4> ; data: {\n    site = nil;\n    type = noticias;\n})",
    "<Module: 0x8e666b0> (entity: Module; id: 0x8cd3180 <x-coredata://B31664A2-091E-43B8-9B36-EB7AF6C27292/Module/p2> ; data: {\n    site = nil;\n    type = fotos;\n})",
    "<Module: 0x8e66a60> (entity: Module; id: 0x8cd3170 <x-coredata://B31664A2-091E-43B8-9B36-EB7AF6C27292/Module/p3> ; data: {\n    site = nil;\n    type = conteudo;\n})"
)
我用CoreData保存数据,我的ManagedObject是这样的

模块h

@interface Module : NSManagedObject

@property (nonatomic, retain) NSString * type;
@property (nonatomic, retain) NSString * site;

@end
模块m

@implementation Module

@dynamic type;
@dynamic site;

@end

我真的不知道我做错了什么,所以任何建议都将不胜感激。谢谢

当您将响应描述符密钥路径设置为
@“content.modulos”
时,您要求RestKit丢弃JSON中的所有较高和同级信息(在映射过程中)。因此,
@parent
信息不存在


您无法真正映射到当前所需的结构中。RestKit希望您将
站点
映射到一个对象,然后将
模块
映射到另一个对象(使用与
RKRelationshipMapping
连接的嵌套映射),并使用关系来连接它们。通过这种方式,您可以使用
@parent
,但不再需要。您的单个响应描述符将使用
站点
映射和
@“content”

谢谢,我不想使用关系,因为这些数据将填充一个表视图,所以当您获取表
模块
然后使用谓词选择所需的
站点
时,会更容易。但是如果是RestKit的设计,我只需要遵循。我不会选择你的答案,因为这不是我想要的,尽管它很有用。再次感谢。谓词可以遍历关系,因此您可以执行表和筛选。要记住的唯一一件事是,如果您使用FRC,那么它不会因关系内容的更改而更新。
@interface Module : NSManagedObject

@property (nonatomic, retain) NSString * type;
@property (nonatomic, retain) NSString * site;

@end
@implementation Module

@dynamic type;
@dynamic site;

@end