0
我試圖從地圖API網址這種反應RestKit responseDescriptor映射(... COM/API /登錄?參數...)沒有KVC
{"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,但我認爲我沒有問題。我的情況只是幾個變化,但我想它應該工作。我錯了什麼?謝謝
我之前嘗試過「api/login」,但它沒有工作。但是現在我嘗試了「/ api/login」並且它可以工作。謝謝 –
我通常會盡可能長地設置基本URL,幷包含尾隨斜槓,因此無處不在路徑模式中。 – Wain
所以你認爲當我總是使用'/ api /'並將其從'pathPatterns'和'getObjectsAtPath'中移除時,最好使用基URL作爲'http:// www ... com/api /'? –