2

我刚刚更新到 RestKit 0.20,我正用头撞我的桌面,试图弄清楚为什么我的 Album 对象无法映射。响应对象没有 keyPath——但之前将其设置为 @"" 有效。

这是返回的数据片段:

[
  {
    id: "337",
    title: "Hockey",
    description: "",
    location: "",
    date_created: "1353424563",
    date_modified: "1353424563",
    featured_image: "album_default.png",
    featured_thumb_link: "http://test1.keepsayk.com//images/album_default.jpg",
    featured_main_link: "http://test1.keepsayk.com/img/album_default.png",
    feat_img_type: "image",
    public: "0",
    default_album: "",
    owner_fname: "Mike",
    owner_lname: "Rose",
    owner_id: "102",
    recent_media: false,
    last_media_added_date: false,
    tags: [ ],
    circles: [],
    media: [ ],
    image_count: 0,
    video_count: 0,
    text_count: 0,
    audio_count: 0,
    comments: [ ],
    scrapbook: [ ]
  },
  {
    id: "336",
    title: "Bull",
    description: "",
    location: "",
    date_created: "1353420585",
    date_modified: "1353420585",
    featured_image: "album_default.png",
    featured_thumb_link: "http://test1.keepsayk.com//images/album_default.jpg",
    featured_main_link: "http://test1.keepsayk.com/img/album_default.png",
    feat_img_type: "image",
    public: "0",
    default_album: "",
    owner_fname: "Mike",
    owner_lname: "Rose",
    owner_id: "102",
    recent_media: false,
    last_media_added_date: false,
    tags: [ ],
    circles: [],
    media: [ ],
    image_count: 0,
    video_count: 0,
    text_count: 0,
    audio_count: 0,
    comments: [ ],
    scrapbook: [ ]
  },
  ...
]

这是我在 App Delegate 中的代码:

// restkit object manager
    _objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://test1.keepsayk.com"]];
    [AFNetworkActivityIndicatorManager sharedManager].enabled = YES;

// restkit object store
    _objectManager.managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:[self managedObjectModel]];
    [_objectManager.managedObjectStore createPersistentStoreCoordinator];
    [_objectManager.managedObjectStore createManagedObjectContexts];

// setup album object
RKEntityMapping *albumEntityMapping = [RKEntityMapping mappingForEntityForName:@"KeepsaykAlbum" inManagedObjectStore:_objectManager.managedObjectStore];
    albumEntityMapping.identificationAttributes = @[@"identifier"];
    [albumEntityMapping addAttributeMappingsFromDictionary:@{ @"id" : @"identifier", @"title" : @"keepsaykTitle", @"description" : @"keepsaykDescription", @"date_created" : @"dateCreated", @"date_modified" : @"dateModified", @"featured_thumb_link" : @"featuredImageThumbLink", @"featured_main_link" : @"featuredImageLink", @"public" : @"isPublic", @"default_album" : @"isDefaultAlbum", @"owner_fname" : @"ownerFirstName", @"owner_lname" : @"ownerLastName", @"owner_id" : @"ownerIdentifier", @"last_media_added_date" : @"dateMediaModified", @"image_count" : @"imageCount", @"video_count" : @"videoCount", @"text_count" : @"textCount", @"audio_count" : @"audioCount", @"scrapbook" : @"scrapbookLayouts" }];

    [_objectManager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:albumEntityMapping pathPattern:@"albums/display/:userID/:apiKey" keyPath:@"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]];

我在另一个类中调用 get 方法——在日志中跟踪资源路径:

- (void)loadObjectsFromResourcePath:(NSString *)resourcePath;
{
    NSLog(@"resource path: %@", resourcePath);

    [RKObjectManager.sharedManager getObjectsAtPath:resourcePath parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
        NSLog(@"mapping result: %@", [mappingResult array]);
        [self stopLoading];
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        NSLog(@"error: %@", error);
        [self stopLoading];
    }];
}

这是我的错误日志:

   2012-12-04 17:48:47.437 Keepsayk Alpha[9036:907] I restkit:RKLog.m:34 RestKit logging initialized...
    2012-12-04 17:48:47.703 Keepsayk Alpha[9036:907] I restkit.support:RKMIMETypeSerialization.m:115 JSON Serialization class 'RKNSJSONSerialization' detected: Registering for MIME Type 'application/json
2012-12-04 17:48:47.696 Keepsayk Alpha[9036:907] resource path: albums/display/102/drrrbSAt6RFLsgHaKiiB6kBIyYRyzxLYinL84Kba
    2012-12-04 17:48:47.708 Keepsayk Alpha[9036:1603] I restkit.network:RKHTTPRequestOperation.m:141 GET 'http://test1.keepsayk.com/albums/display/102/drrrbSAt6RFLsgHaKiiB6kBIyYRyzxLYinL84Kba'
    2012-12-04 17:48:47.711 Keepsayk Alpha[9036:907] error (null), (null)
    2012-12-04 17:48:48.995 Keepsayk Alpha[9036:372f] I restkit.network:RKHTTPRequestOperation.m:158 GET 'http://test1.keepsayk.com/albums/display/102/drrrbSAt6RFLsgHaKiiB6kBIyYRyzxLYinL84Kba' (200)
    2012-12-04 17:48:49.011 Keepsayk Alpha[9036:907] error: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "Unable to find any mappings for the given content" UserInfo=0x1d5b7e40 {DetailedErrors=(
    ), NSLocalizedDescription=Unable to find any mappings for the givn content, keyPath=null}
4

3 回答 3

0

将 keyPath 设置为 nil 而不是 @""

于 2012-12-05T03:54:19.480 回答
0

我的资源路径中缺少初始的“/”。

[_objectManager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:albumEntityMapping pathPattern:@"/albums/display/:userID/:apiKey" keyPath:@"" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]];
于 2012-12-05T19:33:34.400 回答
0

如果有人仍然收到此错误,请检查您的“/”,以便在组合 baseURL 和您的路径时,您不会以“www.mybase.com//blah/blah.json”结尾。此外,如果您更新到最新的 Restkit 代码,截至 2012 年 12 月 8 日,您应该得到一个小修复。Blake 添加了代码以在运行时使用比 1001 更好的描述性进行警告。

于 2012-12-09T04:29:45.980 回答