官网地址https://github.com/AFNetworking/AFNetworking
#import <AFNetworking.h> - (void)viewDidLoad { //GET方法
//创建查询字符串
NSString* str=@"http://apis.juhe.cn/cook/query";
//创建查询条件的字典
NSDictionary* dic=@{@"key":@"912b2db2ecd52723f74c1b7fec8eca38",@"menu":@"红烧肉",@"rn":@"",@"pn":@""};
//创建配置文件
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
//用配置文件初始化AFURLSessionManager
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
//创建GET请求 如果需要POST请求 直接修改此处的Method
NSURLRequest *request = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"GET" URLString:str parameters:dic error:nil];
//创建数据任务
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"%@",responseObject);
NSDictionary* resultDic=[responseObject valueForKey:@"result"];
array=[resultDic valueForKey:@"data"];
NSLog(@"%@",array[]);
[table reloadData];
}
}];
//开始数据任务
[dataTask resume]; }