【发布时间】:2014-02-14 11:38:58
【问题描述】:
我正在尝试从 API url (...com/api/login?params...) 映射此响应
{"success":0,"error":"Some error"}
但我无法让它工作。我有这门课:
@interface LoginResponse : NSObject
@property(nonatomic) NSNumber * Success;
@property(nonatomic) NSString * Error;
@end
这在我的 AppDelegate.m 中有(以及其他有效的响应描述符):
RKObjectMapping *loginMapping = [RKObjectMapping mappingForClass:[LoginResponse class]];
[loginMapping addAttributeMappingsFromDictionary:@{
@"success" : @"Success",
@"error" : @"Error",
}];
RKResponseDescriptor *loginResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:loginMapping
method:RKRequestMethodAny
pathPattern:@"/login"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[manager addResponseDescriptor:loginResponseDescriptor];
我这样称呼它:
RKObjectManager *manager = [RKObjectManager sharedManager];
[manager getObjectsAtPath:@"/api/login"
parameters:@{@"nickname":@"...",@"password":@"test"}
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
{
NSArray* statuses = [mappingResult array];
}
failure:^(RKObjectRequestOperation *operation, NSError *error)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
NSLog(@"Hit error: %@", error);
}];
我得到了这些错误:
Hit error: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No mappable object representations were found at the key paths searched." UserInfo=0x10a2b48d0 {NSLocalizedDescription=No mappable object representations were found at the key paths searched., NSLocalizedFailureReason=The mapping operation was unable to find any nested object representations at the key paths searched: events, points, results
The representation inputted to the mapper was found to contain nested object representations at the following key paths: error, success
This likely indicates that you have misconfigured the key paths for your mappings., keyPath=null, DetailedErrors=(
)}
我就是无法让它工作。我正在尝试查看 RestKit 的 wiki,但我认为我还可以。对我的情况进行了一些更改,但我想它应该可以工作。我有什么错?谢谢
【问题讨论】:
标签: ios ios7 restkit restkit-0.20