我有一个我需要映射的JSON,它有一个没有keyPath的字符串数组,但是还有一个需要映射的属性,它有一个keyPath.我使用的是RestKit 0.21.0,当我更新到RestKit 0.22.0时出现了同样的错误.
JsON:
{ "content": { "site": "www.inf.ufsc.br/~fcdocil","modulos": [ "noticias","fotos","conteudo" ] }}
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})")
但它没有做@ parent.site,我希望是:
SUCCESS ( "<Module: 0x8e54280> (entity: Module; ID: 0x8cd31f0 <x-coredata://B31664A2-091E-43B8-9B36-EB7AF6C27292/Module/p4> ; data: {\n site = www.inf.ufsc.br/~fcdocil;\n type = noticias;\n})","<Module: 0x8e666b0> (entity: Module; ID: 0x8cd3180 <x-coredata://B31664A2-091E-43B8-9B36-EB7AF6C27292/Module/p2> ; data: {\n site = www.inf.ufsc.br/~fcdocil;\n type = fotos;\n})","<Module: 0x8e66a60> (entity: Module; ID: 0x8cd3170 <x-coredata://B31664A2-091E-43B8-9B36-EB7AF6C27292/Module/p3> ; data: {\n site = www.inf.ufsc.br/~fcdocil;\n type = conteudo;\n})")
我正在使用CoreData来保存数据,而我的Managedobject就是这样,
module.h中
@interface Module : NSManagedobject@property (nonatomic,retain) Nsstring * type;@property (nonatomic,retain) Nsstring * site;@end
Module.m
@implementation Module@dynamic type;@dynamic site;@end
我真的没有想到我做错了什么,所以任何建议都会受到赞赏.谢谢
解决方法 当您将响应描述符密钥路径设置为@“content.modulos”时,您要求RestKit丢弃JsON中的所有更高和兄弟信息(在映射过程中).所以@parent信息不存在.您无法真正映射到当前所需的结构. RestKit期望您将站点映射到一个对象,然后将模数映射到另一个对象(使用与RKRelationshipMapPing连接的嵌套映射)并使用关系连接它们.这样你可以使用@parent,但你不再需要.您的单个响应描述符将使用站点映射和@“内容”的关键路径.
总结以上是内存溢出为你收集整理的ios – RestKit映射字符串数组和相同Object的keyPath值全部内容,希望文章能够帮你解决ios – RestKit映射字符串数组和相同Object的keyPath值所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)