AFNetworking and jSON

后端 未结 7 1234
臣服心动
臣服心动 2020-12-28 08:57

I am getting following the json response from a web-service api. I want to extract product data from the json. I also want to implement this using AFNetworking.



        
7条回答
  •  青春惊慌失措
    2020-12-28 09:31

    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'

提交回复
热议问题