RestKit了解在RKResponseDescriptor中放入“pathPattern”和“keyPath”的内容

时间:2015-03-09 19:17:54

标签: ios objective-c restkit

我想使用RestKit,但我不知道如何编写pathPattern和keyPath,json返回:



{
   "photos": {
      "page": 1,
      "pages": 39594,
      "perpage": 10,
      "total": "395933",
      "photo": [
         {
            "id": "16766829152",
            "owner": "32546988@N00",
            "secret": "5b38b40c57",
            "server": "8744",
            "farm": 9,
            "title": "City box lights",
            "ispublic": 1,
            "isfriend": 0,
            "isfamily": 0
         }
      ]
   }
}




错误:

  

错误Domain = org.restkit.RestKit.ErrorDomain Code = 1001"在搜索的关键路径中找不到可映射的对象表示

这就是我现在所拥有的:

#define kBaseRESTURL            @"https://api.flickr.com/services/rest/?method="
#define kSearchMethod           @"flickr.photos.search"

-(void)configureRestKit{

    NSString *url = [NSString stringWithFormat:@"%@%@", kBaseRESTURL, kSearchMethod];
    NSURL *baseURL = [NSURL URLWithString:url];
    AFHTTPClient* client = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
    RKObjectManager *manager = [[RKObjectManager alloc] initWithHTTPClient:client];
    RKObjectMapping* photoMapping = [RKObjectMapping mappingForClass:[Photo class]];
    [photoMapping addAttributeMappingsFromArray:@[@"title"]];
    RKResponseDescriptor *responseDesc = [RKResponseDescriptor responseDescriptorWithMapping:photoMapping method:RKRequestMethodGET pathPattern:@"" keyPath:@"photos.photo" statusCodes:[NSIndexSet indexSetWithIndex:200]];
    [manager addResponseDescriptor:responseDesc];
}

-(void)loadCities : (void(^)(NSArray*))completion {
    [self configureRestKit];
    NSDictionary *queryParams = @{@"api_key" : apiKey,
                                  @"tags" : @"cities",
                                  @"per_page" : @"10",
                                  @"format" : @"json",
                                  @"nojsoncallback" : @"1"
                                 };
    [[RKObjectManager sharedManager] getObjectsAtPath:@"" parameters:queryParams success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
        NSLog(@"ok");
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        NSLog(@" ");
          NSLog(@"error : %@", error);
      }];
}

由于

0 个答案:

没有答案