JSON Serializatioon
- (void)CallWebservice
{
NSString *final_webserviceUrl = [NSString stringWithFormat:@"%@Your URL"];
NSString *parameters = nil;
parameters = [NSString stringWithFormat:@"Parameter1=%@&Parameter2=%@",FirstName,LastName];
NSURL *url = [NSURL URLWithString:final_webserviceUrl];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod: @"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSData *requestData = [NSData dataWithBytes:[parameters UTF8String] length:[parameters length]];
[request setHTTPBody: requestData];
NSError *errorReturned = nil;
NSURLResponse *theResponse =[[NSURLResponse alloc]init];
NSData *responseDataJson = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&errorReturned];
NSString* jsonstring = [[NSString alloc] initWithData:responseDataJson encoding:NSUTF8StringEncoding];
NSLog(@"Request:%@ Response: %@",final_webserviceUrl,jsonstring);
NSData *JSONData = [jsonstring dataUsingEncoding:NSUTF8StringEncoding];
if (errorReturned == nil)
{
[APP_DELEGATE.HUD hide:YES];
id json = [NSJSONSerialization JSONObjectWithData:JSONData options:0 error:nil];
array =[[NSArray alloc] initWithArray:json];
NSLog(@"%@",array);
}
else{
[APP_DELEGATE.HUD hide:YES];
NSLog(@"++++++++DATA PARSING PROBLEM++++++++++");
}
}
Comments
Post a Comment