【问题标题】:Traverse upwards in JSON when mapping using RestKit 0.20使用 RestKit 0.20 映射时在 JSON 中向上遍历
【发布时间】:2013-05-26 21:03:00
【问题描述】:

我有以下 JSON 结构:

{
  "category": "MyCategory"
  "objects": [
    { "id": 1, "name": "A" },
    { "id": 2, "name": "B" },
    { "id": 3, "name": "C" }
  ]
}

我将每个对象映射到一个单独的核心数据实体,如下所示:

RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"Object" inManagedObjectStore:manager.managedObjectStore];
mapping.identificationAttributes = @[ @"id" ];
[mapping addAttributeMappingsFromDictionary:@{ @"name": @"name" }];

如何配置映射以将其共享类别存储在每个对象上?

我想要的是能够像这样在 JSON 中向上遍历:

[mapping addAttributeMappingsFromDictionary:@{ @"name": @"name", @"PARENT.category": @"category" }];

【问题讨论】:

标签: ios objective-c core-data restkit restkit-0.20


【解决方案1】:

截至目前(RestKit 0.20.1),没有办法通过使用映射引擎来做到这一点。

未来

正在开发一个新的元数据功能,可以访问父对象:

[mapping addAttributeMappingsFromDictionary:@{ @"name": @"name", @"@metadata.parentObject.category": @"category" }];

现在

我正在使用 willMapDeserializedResponseBlock 修改我的反序列化响应。我在 RKObjectManager 上添加了一个类别,以便于修改响应:

https://gist.github.com/gunnarblom/5677324

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多