我已经阅读了每篇文章,并完成了教程,我无法弄清楚为什么"对象"数组是空的。在didLoadResponse方法中,我能够在日志中看到[response bodyAsString]。下面是我加载的xml和我用于对象映射的代码。任何帮助将不胜感激。
<?xml version="1.0" encoding="UTF-8"?> <articles>
<article>
<title>This is a test title for article 1</title>
<link>google</link>
<description>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed quis bibendum eros. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</description>
<publicationDate>23 Feb 2012</publicationDate>
</article> </articles>
RKObjectMapping* articleMapping = [RKObjectMapping mappingForClass:[Article class]];
[articleMapping mapKeyPath:@"title" toAttribute:@"title"];
[articleMapping mapKeyPath:@"link" toAttribute:@"link"];
[articleMapping mapKeyPath:@"description" toAttribute:@"description"];
[articleMapping mapKeyPath:@"publicationDate" toAttribute:@"publicationDate"];
//I changed my BaseURL for this post
RKObjectManager* manager = [RKObjectManager objectManagerWithBaseURL:@"myserverpath"];
[manager.mappingProvider setMapping:articleMapping forKeyPath:@"articles.article"];
[manager loadObjectsAtResourcePath:@"/restkit/restkit_test.xml" objectMapping:articleMapping delegate:self];
答案 0 :(得分:1)
你试过......
// RKLogLevelDebug or so..
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
..看看无法完成映射的原因?
您也可以尝试使用rootKeyPath:
articleMapping.rootKeyPath = @"articles.article";