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

ringa_lee

全部回复(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];
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板