RestKit映射操作无法在搜索的关键路径中找到任何嵌套对象表示

时间:2015-03-20 04:57:34

标签: ios objective-c iphone api restkit

我想发布一个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");
}];

非常感谢任何帮助,谢谢

溶液

是删除根密钥路径。

1 个答案:

答案 0 :(得分:2)

  1. 尝试删除路径中的尾随斜杠(@" api / Account / Register"而不是@" api / Account / Register /")
  2. 如果没有任何更改,请打开日志记录到对象映射的跟踪级别RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);您将在控制台中看到其他信息。