ios - 在AFNetworking上怎么用AFJSONRequestOperation来请求数据
ringa_lee
ringa_lee 2017-04-17 16:52:51
0
2
606
ringa_lee
ringa_lee

ringa_lee

répondre à tous(2)
伊谢尔伦

iOS开发小白一枚, 每太明白题主意思.
练习的时候还真没使用到AFJSONRequestOperation, 一直都是用下面的作者的Demo来请求数据的

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

这样从manager来拿operation的实例是木有问题的,你可以command+鼠标,点进去看看manager对operation做了拿些配置。他最后也是把operation添加到operationQueue里面来开始任务的,而不是直接用的start

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];    manager.requestSerializer = [AFJSONRequestSerializer serializer];
AFHTTPRequestOperation *operation = [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSInteger statusCode = operation.response.statusCode;
            //...
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSInteger statusCode = operation.response.statusCode;
            //...
        }];

[manager.operationQueue addOperation:operation];
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal