M
M
Maxim Prigozhenkov2015-02-07 00:12:25
Objective-C
Maxim Prigozhenkov, 2015-02-07 00:12:25

Why does RestKit throw an error when mapping?

Hello everyone!)
I'm trying to delve into the RESTKit library. I delve into using the VKontakte API.
I wrote two methods:

NSURL *baseURL = [NSURL URLWithString:@"https://api.vk.com/method/"];
    AFHTTPClient *client = ;

    RKResponseDescriptor *responseDescriptor =
    [RKResponseDescriptor responseDescriptorWithMapping:profilesMapping
                                                 method:RKRequestMethodGET
                                            pathPattern:@"users.get?user_id=1"
                                                keyPath:@"response"
                                            statusCodes:[NSIndexSet indexSetWithIndex:200]];
    
    [objectManager addResponseDescriptor:responseDescriptor];

This is the RestKit configuration method
NSDictionary *params = @{@"fields": @"photo_max"};
    
    [[RKObjectManager sharedManager] getObjectsAtPath:@"users.get?user_id=1"
                                           parameters:params
                                              success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){
                                               NSLog(@"%@", mappingResult.array);
                                           }
                                              failure:^(RKObjectRequestOperation *operation, NSError *error){
                                                  NSLog(@"%@", error);
                                                  NSLog(@":c");
                                              }
     ];

And this one is already loading JSON and in fact should map it, but it gives an error:
No mappable object representations were found at the key paths searched.", keyPath=null, NSLocalizedDescription=No response descriptors match the response loaded.

I can't figure out where exactly is the error?
PS The request itself looks like this https://api.vk.com/method/users.get?user_id=1&fiel...

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
S
Sergey Buravtsov, 2015-05-27
@Waka_Waka

user_id=1 - also a parameter, it should be in params, but not in pattern/path

RKObjectMapping *profilesMapping = [RKObjectMapping mappingForClass:[LVKUser class]];
    [profilesMapping addAttributeMappingsFromArray:@[@"uid",
                                                     @"first_name",
                                                     @"last_name",
                                                     @"nickname"]];
    
    RKResponseDescriptor *responseDescriptor =
    [RKResponseDescriptor responseDescriptorWithMapping:profilesMapping
                                                 method:RKRequestMethodGET
                                            pathPattern:@"users.get"
                                                keyPath:@"response"
                                            statusCodes:[NSIndexSet indexSetWithIndex:200]];
    
    [objectManager addResponseDescriptor:responseDescriptor];
    
    NSDictionary *params = @{@"fields": @"nickname", @"user_id": @"1"};
    
    [[RKObjectManager sharedManager] getObjectsAtPath:@"users.get"
                                           parameters:params
                                              success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){
                                                  NSLog(@"%@", mappingResult.array);
                                              }
                                              failure:^(RKObjectRequestOperation *operation, NSError *error){
                                                  NSLog(@"%@", error);
                                                  NSLog(@":c");
                                              }
     ];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question