我正在尝试从 Web 服务读取一个简单的 json 字符串响应:
假设我有这个映射:
RKObjectMapping* loginRequestMapping = [RKObjectMapping requestMapping];
[loginRequestMapping addAttributeMappingsFromDictionary:@{
@"userName" : @"UserName",
@"password" : @"Password"
}];
RKRequestDescriptor* loginReq = [RKRequestDescriptor requestDescriptorWithMapping:loginRequestMapping objectClass:[LoginRequest class] rootKeyPath:nil method:RKRequestMethodPOST];
[objectManager addRequestDescriptor:loginReq];
我试过这个请求:
LoginRequest* loginReq = [LoginRequest new];
loginReq.userName = @"username";
loginReq.password = @"1234567890";
__block NSString* token;
[objectManager postObject:loginReq
path:@"/sendboxapi/api/login"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
token = [mappingResult firstObject];
NSLog(@"RESULT : %@", token);
}
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);
}];
原始响应具有以下格式:“47c4e389-be2b-466b-b015-c8d5682c4f0a”
我收到此错误:命中错误:错误域 = org.restkit.RestKit.ErrorDomain 代码 = -1017“加载了内容类型为 'application/json' 的无法处理的响应 (200)”
什么是正确的 RKObjectMapping 设置以能够从 web 服务读取此字符串?
谢谢