Thursday, March 21, 2013

Get Json from iPhone Objective C

Here the code to connect to a web service a receive the data in json format and print it to the console 

NSURL *url = [NSURL URLWithString:@"here your web app url"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:@"GET"];
NSURLResponse *theResponse = NULL;
NSError *theError = NULL;
NSData *theResponseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error :&theError]; NSString *jsonString = [[NSString alloc] initWithData:theResponseData encoding:NSUTF8StringEncoding]; NSLog(jsonString);
view raw gistfile1.m hosted with ❤ by GitHub