服务器响应 "java.lang.Integer cannot be cast to java.lang.Double"

Server response "java.lang.Integer cannot be cast to java.lang.Double"

我正在尝试使用 NSURLSession 发出 post 请求。我需要发送包含双精度值的数据。我使用 NSNumberNSDictionary 中存储双精度值。我正在 post 收集这样的数据:

 -(void)sortJobsWithLat:(float)lat longt:(float)longt distance:(float)distance budget:(NSInteger)budget rating:(NSInteger)rating page:(NSUInteger)page {

    NSError *error;
    NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];

    NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];

    NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BaseURLJobs,SearchJobs]];
    NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
    NSLog(@"url : %@", url);

      NSDictionary *params=[[NSDictionary alloc]initWithObjectsAndKeys:[NSNumber numberWithDouble:lat] ,@"latitude",[NSNumber numberWithDouble:longt],@"longitude", [NSNumber numberWithDouble:distance],@"distance",   [NSString stringWithFormat:@"%ld",(long)budget] ,@"budget", [NSString stringWithFormat:@"%ld",(long)rating],@"rating", [NSString stringWithFormat:@"%ld",page],@"pageNo",nil];

    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:params options:kNilOptions error:&error];


    NSLog(@"params : %@",params);

    [urlRequest addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [urlRequest addValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [urlRequest setHTTPMethod:@"POST"];
    [urlRequest setHTTPBody:jsonData];

    NSData *postData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error];
    [urlRequest setHTTPBody:postData];

    dataTask =[defaultSession dataTaskWithRequest:urlRequest
                                completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                    if(error == nil)
                                    {
                                        NSError *jsonError;
                                        NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data
                                                                                                   options:kNilOptions
                                                                                                     error:&jsonError];
                                        NSLog(@"json object : %@",jsonObject);
                                    }
                                    else{
                                        [AppDel showAlertWithMessage:error.localizedDescription andTitle:nil];
                                    }
                                }];
    [dataTask resume];
}

当我使用 NSLog 打印参数时,它打印如下:

    params : {
    budget = 1000;
    distance = 50;
    latitude = "30.73979949951172";
    longitude = "76.78269958496094";
    pageNo = 0;
    rating = 4;
}

服务器正在返回如下响应:

json object : {
    error = "Internal Server Error";
    exception = "java.lang.ClassCastException";
    message = "java.lang.Integer cannot be cast to java.lang.Double";
    path = "/jobs/searchJobs";
    status = 500;
    timestamp = 1471760398842;
}

此错误清楚地表明服务器无法将整数值转换为 double.I由于距离参数而出现此错误。我将距离作为双精度值传递,然后服务器如何将其作为整数值找到?

问题是服务器无法识别这些参数。服务器部分工作正常,因为我已经使用 Swagger UI 为 Google Chrome 发送了一个 POST,它工作得很好。

我收到此错误是因为我将 50.0 作为双精度值发送。 Objective C 自动将其转换为整数。所以服务器正在获取整数值,但无法转换该值。我已在服务器上进行更改以解决此错误..