RestKit 0.2 - 错误域= org.restkit.RestKit.ErrorDomain代码= 1001

时间:2012-12-05 00:03:50

标签: restkit

我刚刚更新到RestKit 0.20,我正在敲打我的桌面,试图找出我的专辑对象无法映射的原因。响应对象没有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}

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

我错过了资源路径中的初始“/”。

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

答案 2 :(得分:0)

如果有人仍然收到此错误,请检查您的“/”,以便在组合baseURL和您的路径时,您最终不会得到“www.mybase.com//blah/blah.json”。此外,如果您更新到最新的Restkit代码,从12/8/2012开始,您应该稍微修复一下。 Blake添加了代码,用于在运行时使用比1001更好的描述性警告。

相关问题