Ios RestKit 0.20嵌套对象映射(到对象树的路径不同)
映射嵌套对象值时遇到问题 我得到了两个具有以下属性的对象: (a) (b) ..因此配置文件包含一个输入对象。当我用RestKit(0.20)映射对象时,我得到如下结果:Ios RestKit 0.20嵌套对象映射(到对象树的路径不同),ios,objective-c,json,restkit,restkit-0.20,Ios,Objective C,Json,Restkit,Restkit 0.20,映射嵌套对象值时遇到问题 我得到了两个具有以下属性的对象: (a) (b) ..因此配置文件包含一个输入对象。当我用RestKit(0.20)映射对象时,我得到如下结果: { myAwesomeInput_test:{"value":"xyz","title":"a title"}} RKObjectMapping* inputMapping = [RKObjectMapping requestMapping]; [inputMapping addAttributeMappingsFromAr
{ myAwesomeInput_test:{"value":"xyz","title":"a title"}}
RKObjectMapping* inputMapping = [RKObjectMapping requestMapping];
[inputMapping addAttributeMappingsFromArray:@[@"value"]];
RKRequestDescriptor *reqDescInput = [RKRequestDescriptor requestDescriptorWithMapping:inputMapping objectClass:[Input class] rootKeyPath:nil];
RKObjectMapping* searchProfile = [RKObjectMapping requestMapping];
RKRequestDescriptor *reqDescSearchProfile = [RKRequestDescriptor requestDescriptorWithMapping:searchProfile objectClass:[SearchProfile class] rootKeyPath:nil];
[searchProfile addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"myAwesomeInput" toKeyPath:@"myAwesomeInput_test" withMapping:inputMapping]];
我想要实现的是:
{myAwesomeInput_test:"xyz"}
所以我不想映射“Input”,只想映射Input.value。这可能吗
目前,我的代码如下所示:
{ myAwesomeInput_test:{"value":"xyz","title":"a title"}}
RKObjectMapping* inputMapping = [RKObjectMapping requestMapping];
[inputMapping addAttributeMappingsFromArray:@[@"value"]];
RKRequestDescriptor *reqDescInput = [RKRequestDescriptor requestDescriptorWithMapping:inputMapping objectClass:[Input class] rootKeyPath:nil];
RKObjectMapping* searchProfile = [RKObjectMapping requestMapping];
RKRequestDescriptor *reqDescSearchProfile = [RKRequestDescriptor requestDescriptorWithMapping:searchProfile objectClass:[SearchProfile class] rootKeyPath:nil];
[searchProfile addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"myAwesomeInput" toKeyPath:@"myAwesomeInput_test" withMapping:inputMapping]];
编辑:(已解决)
好的,我解决了。希望这是人们应该做的。您可以直接从字典中查找地址
RKObjectMapping* searchProfile = [RKObjectMapping requestMapping];
[aeSearchProfile addAttributeMappingsFromDictionary:@{
@"myAwesomeInput.value": @"myAwesomeInput_test"
}];
RKRequestDescriptor *reqDescSearchProfile = [RKRequestDescriptor requestDescriptorWithMapping:searchProfile objectClass:[SearchProfile class] rootKeyPath:nil];
使用关键路径,而不是多个映射。 试试这个:
RKObjectMapping* searchProfile = [RKObjectMapping requestMapping];
[searchProfile addAttributeMappingsFromDictionary:@{ @"myAwesomeInput.value" : @"myAwesomeInput_test" }];
RKRequestDescriptor *reqDescSearchProfile = [RKRequestDescriptor requestDescriptorWithMapping:searchProfile objectClass:[SearchProfile class] rootKeyPath:nil];
谢谢,我想我们是在同一时间找到/发布了答案(看看发布的时间:D无论如何,对于拥有相同探测器的其他人来说,这将是一个又好又快的方法。再次感谢