JSON parsing using GET method in iOS
In this post , we will know about how to send or receive JSON data using GET parameters .
Step 1 : Create a new Xcode project .
Step 2: Update info.plist in your project.
1) Add App Transport Security Settings in the plist .
2) Add Allow Arbitrary Loads to YES as a subtype of App Transport Security Settings.
Step 3 : Add the following code in ViewDidLoad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; // Create a mutable request | |
[request setURL:[NSURL URLWithString:@"YOUR URL"]]; // add your url | |
[request setHTTPMethod:@"GET"]; // specify the JSON type to GET | |
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; // intialiaze NSURLSession | |
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { // Add your parameters in blocks | |
NSString *replyStr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; | |
NSLog(@"Get your response == %@", replyStr); | |
}] | |
resume]; |
For JSON parsing using post parameters view my post on JSON using POST parameters
Thank You :)
Thanks for this beautiful post IOS. It is really good for the beginners and I also liked the post.
ReplyDeleteIOS Training in Bangalore
IOS Training in Marathahalli