我想发布一个User
对象的请求进行注册,但我收到此错误:
The mapping operation was unable to find any nested object representations at the key paths searched
这是我发布请求的代码:
User * user = [[User alloc]init];
user.UserName = _userNameTextField.text;
user.Password = _passwordTextField.text;
user.ConfirmPassword = _passwordTextField.text;
user.Email = _emailTextField.text;
// {
// "Email": "sample string 1",
// "UserName": "sample string 2",
// "Password": "sample string 3",
// "ConfirmPassword": "sample string 4"
// }
RKObjectManager * objectmanager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"url"]];
RKObjectMapping * userMapping = [RKObjectMapping requestMapping];
[userMapping addAttributeMappingsFromArray:@[@"Email",@"UserName",@"Password",@"ConfirmPassword"]];
RKRequestDescriptor * registrationDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:userMapping objectClass:[User class] rootKeyPath:@"api/Account/Register/" method:RKRequestMethodPOST];
[objectmanager addRequestDescriptor:registrationDescriptor];
[objectmanager postObject:user path:@"api/Account/Register/" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"Success");
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Fail");
}];
非常感谢任何帮助,谢谢
溶液
是删除根密钥路径。
答案 0 :(得分:2)
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
您将在控制台中看到其他信息。