2012-03-08 173 views
0

我在映射简单JSON对象极其卡住:RestKit对象映射 - 解析嵌套数组

{"articles": 
[{"id":"354633","lat":"51.501","lng":"-0.125","type":"railwaystation","title":"Westminster tube station","url":"http:\/\/en.wikipedia.org\/w\/index.php?curid=354633","distance":"53m"}, 

{"id":"92601","lat":"51.5011","lng":"-0.125","type":"railwaystation","title":"17 - Westminster tube station","url":"http:\/\/en.wikipedia.org\/w\/index.php? curid=92601","distance":"62m"},  

{"id":"92598","lat":"51.5011","lng":"-0.125","type":"railwaystation","title":"34 -Westminster tube station","url":"http:\/\/en.wikipedia.org\/w\/index.php?curid=92598","distance":"62m"}] 
} 

我真的由我有问题困惑,因为这是几乎相同的JSON在RestKit映射指南。

我的代码是:

self.articleMapper = [RKObjectMapping mappingForClass:[WikiArticle class]]; 
[self.articleMapper mapKeyPath:@"title" toAttribute:@"title"];  
[[RKObjectManager sharedManager].mappingProvider setMapping:self.articleMapper forKeyPath:@"articles"]; 

我得到下面的错误日志中:

restkit.object_mapping:RKObjectMappingOperation.m:339 Did not find mappable attribute value keyPath 'title' 
restkit.object_mapping:RKObjectMappingOperation.m:557 Mapping operation did not find any mappable content 
restkit.object_mapping:RKObjectMapper.m:308 The following operations are in the queue:() 
restkit.object_mapping:RKObjectMapper.m:323 Finished performing object mapping. Results: {} 

预先感谢帮助我的东西很简单 - 我一直我的头撞了几个小时!

-Alex

回答

0

我想你把它的方式是这样的:

[objectManager loadObjectsAtResourcePath:url delegate:self block:^(RKObjectLoader* loader) { 
     loader.objectMapping = [objectManager.mappingProvider objectMappingForClass:[WikiArticle class]]; 
    }]; 

最好尝试:

[objectManager loadObjectsAtResourcePath:url delegate:self];