【问题标题】:RestKit Object Mapping - Parsing A Nested ArrayRestKit 对象映射 - 解析嵌套数组
【发布时间】:2012-03-08 07:47:42
【问题描述】:

我非常坚持映射一个简单的 JSON 对象:

{"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"}]
}

我对我遇到的问题感到非常困惑,因为这与 RestKit 映射指南中的 JSON 几乎相同。

我的代码是:

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: {}

提前感谢您帮助我解决了这么简单的问题——我已经为此苦苦挣扎了好几个小时了!

-亚历克斯

【问题讨论】:

    标签: ios restkit


    【解决方案1】:

    我想你是这样称呼它的:

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

    最好试试:

    [objectManager loadObjectsAtResourcePath:url delegate:self];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-30
      • 1970-01-01
      • 1970-01-01
      • 2014-02-25
      相关资源
      最近更新 更多