没有KVC的RestKit responseDescriptor映射

时间:2014-02-14 11:38:58

标签: ios ios7 restkit restkit-0.20

我正在尝试从API网址(... 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的维基,但我想我没事。我的情况只有一些变化,但我想它应该有效。我错了什么?感谢

1 个答案:

答案 0 :(得分:1)

您的问题是与您的基本网址相关的路径模式。他们目前不匹配。

我会将韧皮网址设置为:...com/api/。然后,响应描述符路径模式和获取对象路径都是login。现在一切都很匹配。

如果基本网址设置为...com,那么两者的路径模式必须为/api/login

相关问题