Answer the question
In order to leave comments, you need to log in
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];
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");
}
];
No mappable object representations were found at the key paths searched.", keyPath=null, NSLocalizedDescription=No response descriptors match the response loaded.
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question