#pragma mark 获取
- (void)qingqiushujuUrl:(NSString *)urlString bodyDic:(NSDictionary *)bodyDic{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[manager POST:urlString parameters:bodyDic success:^(AFHTTPRequestOperation *operation, id responseObject){
if (!responseObject) {
return;
}
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
_dataArr = [[NSMutableArray alloc] init];
NSDictionary *dictionary = [dic objectForKey:@"data"];
for (NSDictionary *appDic in dictionary) {
[_dataArr addObject:[TeachPlanModel modelWithDic:appDic]];
}
[_tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSLog(@"数据请求失败");
}];
}
//停止网络请求
[manager.operationQueue cancelAllOperations];
本文介绍如何使用AFNetworking库在iOS应用中发送POST请求,并正确解析JSON响应数据。通过实例演示了从URL字符串和参数字典创建AFHTTPRequestOperationManager对象,发送请求,解析JSON响应为字典,并将数据存储到数组中。同时,文章还包含了网络请求成功与失败时的回调处理逻辑。
2893

被折叠的 条评论
为什么被折叠?



