• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 使用restkit api objective-c 调用Web服务时出错

[复制链接]
菜鸟教程小白 发表于 2022-12-11 18:58:30 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在尝试调用网络服务并上传图片,

映射有问题,我花了好几个小时都没有成功。我得到的错误是:

Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No mappable object representations were found at the key paths searched." UserInfo={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: user The representation inputted to the mapper was found to contain nested object representations at the following key paths: message, success This likely indicates that you have misconfigured the key paths for your mappings., keyPath=null, DetailedErrors=( )}

还有调用网络服务的方法

[SVProgressHUD show];

        [delegate.objectManager.HTTPClient.defaultHeaders setValue"application/x-www-form-urlencoded" forKey"content-type" ];

        RKObjectMapping *responseMapping = [RKObjectMapping mappingForClass:[SignUpResponse class]]; //create response and request mapping

        [responseMapping addAttributeMappingsFromDictionary{@"phone": @"phone",
                                                              @"device_type": @"device_type",
                                                              @"device_token": @"device_token",
                                                              @"type": @"type",
                                                              @"email": @"email",
                                                              @"identity": @"identity",
                                                              @"date": @"date",
                                                              @"status": @"status",
                                                              @"name": @"name",
                                                              @"activation": @"activation",
                                                              @"image": @"image",
                                                              @"id": @"id"
                                                              }];

        RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:responseMapping
                                                                                                method:RKRequestMethodPOST
                                                                                           pathPattern"AgentRegister"
                                                                                               keyPath"user"
                                                                                           statusCodes:[NSIndexSet indexSetWithIndex:200]];

        [delegate.objectManager.defaultHeaders setValue"application/x-www-form-urlencoded" forKey"content-type" ];
        delegate.objectManager.requestSerializationMIMEType =RKMIMETypeFormURLEncoded;


        [delegate.objectManager removeResponseDescriptor:responseDescriptor];

        [delegate.objectManager addResponseDescriptor:responseDescriptor];

        NSString *fcmToken = [FIRInstanceID instanceID].token;

        SignUpRequest *signUpRequest = [[SignUpRequest alloc]init];
        signUpRequest.phone = txtPhoneNumber.text;
        signUpRequest.email = txtEmail.text;
        signUpRequest.identity=txtIdOrCity.text;
        signUpRequest.device_type=@"IOS";
        signUpRequest.device_token=fcmToken;
        signUpRequest.type=@"1";


        UIImage *image = [UIImage imageNamed"Logo"];


        // Serialize the Article attributes then attach a file
        NSMutableURLRequest *request = [[RKObjectManager sharedManager] multipartFormRequestWithObject:signUpRequest method:RKRequestMethodPOST path"AgentRegister" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
            [formData appendPartWithFileData:UIImagePNGRepresentation(image)
                                        name"image"
                                    fileName:@"photo.png"
                                    mimeType:@"application/x-www-form-urlencoded"];
        }];

        RKObjectRequestOperation *operation = [[RKObjectManager sharedManager] objectRequestOperationWithRequest:request success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){

            [SVProgressHUD dismiss];
            if(mappingResult.array.count !=0){
                [self performSegueWithIdentifier:@"goToVerify" sender:self];
            }else{

            }

            [delegate.objectManager removeResponseDescriptor:responseDescriptor];
        }failure:^(RKObjectRequestOperation *operation, NSError *error){
            [SVProgressHUD dismiss];
            NSLog(@"%@",error.description);
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@".."
                                                                           message:@"حدث خطاء ما .. حاول مرة اخري" preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            }];
            [alert addActionkAction];
            [self presentViewController:alert animated:YES completion:nil];
            [delegate.objectManager removeResponseDescriptor:responseDescriptor];

        }];
        [[RKObjectManager sharedManager] enqueueObjectRequestOperationperation];

    }



Best Answer-推荐答案


此错误告诉您 user 路径中没有可用的内容。例如,如果您的响应是 JSON,则没有名为 user 的根键,只有 messagesuccess:

{ "user": "<- 这个键不存在", "message": "<- 这里有东西", "success": "<- 这里也有东西" }

您很可能需要将 keyPathuser 更改为 success.user

关于ios - 使用restkit api objective-c 调用Web服务时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46686658/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap