AFNetworking and jSON AFNetworking and jSON ios ios

AFNetworking and jSON


NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"link"]];AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request     success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {        NSDictionary *jsonDict = (NSDictionary *) JSON;        NSArray *products = [jsonDict objectForKey:@"products"];        [products enumerateObjectsUsingBlock:^(id obj,NSUInteger idx, BOOL *stop){            NSString *productIconUrl = [obj objectForKey:@"icon_url"];        }];    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response,        NSError *error, id JSON) {            NSLog(@"Request Failure Because %@",[error userInfo]);     }];[operation start];

Try this.

Update 1: You can try this https://github.com/SSamanta/SSRestClient

Update 2: https://github.com/SSamanta/SSHTTPClient (Using Swift)

Available Pod : pod 'SSHTTPClient', '~>1.2.2'


if you're using AFNetworking 3.0, AFJSONRequestOperation doesn't exist anymore, you have to use AFHTTPSessionManager :

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];[manager GET:@"http://example.com/resources.json" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {    NSLog(@"JSON: %@", responseObject);} failure:^(NSURLSessionTask *operation, NSError *error) {    NSLog(@"Error: %@", error);}];


To parse JSON with AFNetworking, just create a subclass and add the following during initialization.

[self registerHTTPOperationClass:[AFJSONRequestOperation class]];

Then calling a method like GET:parameters:completion: will call the completion block with an NSDictionary as the response parameter (assuming the JSON is valid).

To download the images, assuming you want to display them, check out UIImageView+AFNetworking.