这是我的代码:
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]];
//Create an URLRequest
NSURL *url = [NSURL URLWithString:@"...my url ..."];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
//Create POST Params and add it to HTTPBody
NSString *params = [NSString stringWithFormat:@"p_no=%@&app_key=%@&lat=%f&lan=%f&lat_t=%f&lan_t=%ftime=%@&date=%@",phoneSaved,appKeySaved,pickUpLocLat,pickUpLocLng,pickUpDestLat,pickUpDestLng,[dateFormatter stringFromDate:now],date_String];// my params which i think are good
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
//Create task
NSURLSessionDataTask * dataTask =[defaultSession dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"%@",data);
NSDictionary *dictVerify = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
//NSLog(@"%@",dictVerify);
NSString *errorReturn = [dictVerify objectForKey:@"error"];
//NSString *message = [dictVerify objectForKey:@"message"];
if (!errorReturn) {
NSLog(@"amazing : %@",dictVerify); // this logs the serialized data
} else {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Verification"
message:errorReturn
preferredStyle:UIAlertControllerStyleAlert];
//We add buttons to the alert controller by creating UIAlertActions:
UIAlertAction *actionOk = [UIAlertAction actionWithTitle:@"Ok"
style:UIAlertActionStyleDefault
handler:nil]; //You can use a block here to handle a press on this button
[alertController addAction:actionOk];
[self presentViewController:alertController animated:YES completion:nil];
}
}];
[dataTask resume];
回复是:
count = 1;
data = (
{
"base_fare" = "20.00";
"c_no" = WB60000;
"c_type" = 1;
"car_type_label" = Mini;
color = white;
"d_id" = bZ;
"d_type" = 1;
"driver_type_label" = "Individual Driver";
"f_name" = Saikat;
"l_name" = Singh;
status = 1;
"waiting_time" = 8;
}
);
这里只缺少两个键,它们是lat和lan,位于Web服务的下方:
{
"data": [
{
"d_id": "bZ",
"lat": "22.588305",
"lan": "88.410210",
"d_type": "1",
"c_type": "1",
"status": "1",
"driver_type_label": "Individual Driver",
"car_type_label": "Mini",
"c_no": "WB60000",
"color": "white",
"f_name": "Saikat",
"l_name": "Singh",
"waiting_time": "8",
"base_fare": "20.00"
}
],
"count": 1
}
我找不到任何问题,因为数据正在返回但只缺少密钥,我之前没有遇到过这种问题,请帮忙。如果您需要更多信息,请发表评论我会相应更新详细信息。