用AFNetWorking 进行get请求 jeson 、非jeson 数据

#pragma mark -非JSON数据类型-
-(void)dataGetRequest:(NSString*)urlStr{
    //数据请求队列的管理器,单例
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    //这样设置 请求的数据是data,不要解析
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    //发送get请求
    [manager GET:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"%@",[responseObject class]);
        self.imageView.image = [UIImage imageWithData:responseObject];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error:%@",error);
    }];
    
}

#pragma mark -GET请求 JSON数据-
-(void)jsonGetRequest:(NSString*)urlStr{
    
    //数据请求队列的管理器,单例
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    //这样设置就会进行json解析
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", nil];
    //发送get请求
    [manager GET:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //自动解析
        NSLog(@"responseObject:%@",responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error:%@",error);
    }];
    
}


你可能感兴趣的:(json,入门,网络,数据,block)