Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON dealy response
    text
    copied!<p>I am using JSON to get data from web service.The problem is When i call web service and due to slow response my app become unresponsive for few seconds and some times crash.</p> <p>I search a lot and found that by making Asynchronous call instead of Synchronous call can solve problem. But how to use asynchronous call that i don't know.</p> <p>My code is like..</p> <pre><code>SBJSON *json = [SBJSON new]; json.humanReadable = YES; responseData = [[NSMutableData data] retain]; NSString *service = @"/Get_NearbyLocation_list"; double d1=[[[NSUserDefaults standardUserDefaults]valueForKey:@"LATITUDE"] doubleValue]; NSLog(@"%f",d1); double d2=[[[NSUserDefaults standardUserDefaults]valueForKey:@"LONGITUDE"] doubleValue]; NSLog(@"%f",d2); NSString *requestString = [NSString stringWithFormat:@"{\"current_Lat\":\"%f\",\"current_Long\":\"%f\"}",d1,d2]; NSLog(@"request string:%@",requestString); // NSString *requestString = [NSString stringWithFormat:@"{\"GetAllEventsDetails\":\"%@\"}",service]; NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]]; NSString *fileLoc = [[NSBundle mainBundle] pathForResource:@"URLName" ofType:@"plist"]; NSDictionary *fileContents = [[NSDictionary alloc] initWithContentsOfFile:fileLoc]; NSString *urlLoc = [fileContents objectForKey:@"URL"]; urlLoc = [urlLoc stringByAppendingString:service]; NSLog(@"URL : %@",urlLoc); NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: urlLoc]]; NSString *postLength = [NSString stringWithFormat:@"%d", [requestData length]]; [request setHTTPMethod: @"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody: requestData]; // self.connection = [NSURLConnection connectionWithRequest:request delegate:self]; NSError *respError = nil; NSData *returnData= [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: &amp;respError ]; if (respError) { UIAlertView *alt=[[UIAlertView alloc]initWithTitle:@"Internet connection is not Available!" message:@"Check your network connectivity" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; [alt performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES]; [alt release]; [customSpinner hide:YES]; [customSpinner show:NO]; } else { NSString *responseString = [[NSString alloc] initWithData:returnData encoding: NSUTF8StringEncoding]; NSLog(@" %@",responseString); NSDictionary *results = [[responseString JSONValue] retain]; NSLog(@" %@",results); </code></pre> <p>thanks in advance..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload