我是ios的新手,在我的项目中,我使用NSUrlConnection
来集成服务,但是当我向服务器发送请求时,我得到了一个空响应并且出现此错误:
JSONValue失败。错误跟踪是:( “Error Domain = org.brautaset.JSON.ErrorDomain Code = 11 \”字符串的意外结束\“UserInfo = {NSLocalizedDescription =意外结束字符串}” )
但是当我签入邮件时,客户端响应来自服务器
但为什么回复没有进入我的应用程序请帮我一个。
dictionary is {
MedicaidId = 101229518299;
coriders = (
2870862
);
escort = {
name = "";
relation = 2;
};
schUrgentCare = 0;
test = tripComments;
transportMode = Regular;
tripDate = "10/02/2016 - 09:32 PM";
tripLegs = (
{
ApptTime = "10/02/2016 - 09:32 PM";
TerritoryId = 3;
TripLegType = 4;
destination = {
Address1 = "335 VANDALIA ST";
Address2 = "";
City = LAPAZ;
PhoneNo = 5747842191;
ProviderId = 0;
State = IN;
Zip = 46537;
};
source = {
Address1 = "335 VANDALIA ST";
Address2 = "";
City = LAPAZ;
PhoneNo = 5747842191;
ProviderId = 1;
State = IN;
Zip = 46537;
};
}
);
tripNotes = {
HasCarSeat = 0;
HasSplEquipment = 0;
NeedLiftVan = 0;
TransferWheelChair = 0;
WheelChairCanFold = 1;
WheelChairCanNotFold = 1;
};
urgentCare = 0;
}
-(void)serviceCalling :(NSDictionary*)mydictionary{
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:mydictionary
options:kNilOptions
error:&error];
NSString *urlStr = [NSString stringWithFormat:@"%@Trip/Create",kServerBaseURL];
NSLog(@"urlStr --->> %@",urlStr);
NSURL *serviceUrl=[NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:serviceUrl];
[request setTimeoutInterval:120];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:AccessToken forHTTPHeaderField:@"Authorization"];
[request setValue:@"json" forHTTPHeaderField:@"Data-Type"];
[request setHTTPBody:jsonData];
NSURLConnection *connectionManager = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (connectionManager) {
NSLog(@"connected");
}
else{
NSLog(@"not connected");
}
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[downloadedMutableData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
[MBProgressHUD hideHUDForView:self.view animated:YES];
if (error.code == NSURLErrorTimedOut){
NSLog(@"REquest time out");
}
else{
NSLog(@"Response --->> ERRORRRRRR");
}
}
// This method is call,when server response is success
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSDictionary *responeDict = [[[NSString alloc]initWithData:downloadedMutableData encoding:NSUTF8StringEncoding] JSONValue];
NSLog(@"Response --->> %@",responeDict);
}