我正在尝试将我的核心数据“组件”实体映射到此响应 JSON 中的“热点”键路径,但它只到达数组对象,因此它不会映射。我不知道我的问题是映射还是响应描述符或两者的组合。
"result" : {
"type" : "Slidedeck",
"id" : 81,
"name" : "Brendantest",
"slides" : [
  {
    "thumb" : "http:\/\/api.idetailapp.review.thingee.com\/v4\/resources\/1294\/download\/slide?thumb=true",
    "id" : 1294,
    "notes" : "",
    "label" : "",
    "order" : 1,
    "parent_id" : 81,
    "file" : "slide-20.jpg",
    "components" : {
      "hotspots" : [
        {
          "x" : 205,
          "options" : "embedded",
          "type" : "video",
          "id" : 6082,
          "y" : 453,
          "assets" : [
            {
              "thumb" : "\/system\/asset_objects\/14\/original_thumb\/14.png",
              "id" : 14,
              "parent_id" : 6082,
              "file" : "slide_15_chart_animation_ipad_r03.mov",
              "url" : "http:\/\/api.idetailapp.review.thingee.com\/v4\/resources\/14\/download\/asset"
            }
          ],
          "parent_id" : 1294,
          "width" : 320,
          "height" : 246
        }
      ]
    },
    "url" : "http:\/\/api.idetailapp.review.thingee.com\/v4\/resources\/1294\/download\/slide"
  }
],
"version" : "0.43"
} }
这是我的 RKEntityMapping:
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"Component"
                                               inManagedObjectStore:[RKManagedObjectStore  defaultStore]];
mapping.identificationAttributes = @[ @"componentID" ];
[mapping addAttributeMappingsFromDictionary:@{@"id": @"componentID",
                                              @"parent_id": @"parentID"
                                              }];
[mapping addAttributeMappingsFromArray:@[@"x", @"y", @"width", @"height", @"type", @"options"]];
这是我的响应描述符:
componentResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:componentEntityMapping 
method:RKRequestMethodAny pathPattern:nil  
keyPath:@"result.slides.components.hotspots"         statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
我输入了一个 RestKit/ObjectMapping 调试跟踪并得到以下输出:
Asked to map source object (
    {
    assets =         (
                    {
            file = "slide_15_chart_animation_ipad_r03.mov";
            id = 14;
            "parent_id" = 6082;
            thumb = "/system/asset_objects/14/original_thumb/14.png";
            url = "http://api.idetailapp.review.thingee.com/v4/resources/14/download/asset";
        }
    );
    height = 246;
    id = 6082;
    options = embedded;
    "parent_id" = 1294;
    type = video;
    width = 320;
    x = 205;
    y = 453;
}
以及进一步的调试信息:
将 keyPath 'id' 处的值转换为类型 'NSNumber' 的表示失败:错误域 = org.restkit.RKValueTransformers.ErrorDomain 代码 = 3002“值转换失败”(6082)UserInfo = 0x12479350 {NSLocalizedDescription = 预期inputValue类型NSNull,但有一个__NSArrayI.}" ),