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


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];
view raw GETJSON hosted with ❤ by GitHub
For JSON parsing using post parameters view my post on JSON using POST parameters 


Thank You :)

Comments

  1. Thanks for this beautiful post IOS. It is really good for the beginners and I also liked the post.
    IOS Training in Bangalore
    IOS Training in Marathahalli

    ReplyDelete

Post a Comment

Popular Posts