标签:
使用AFNetWorking之前要先下载
官网下载2.5版本:http://afnetworking.com/
下载完成后先导入
然后导入
#import "AFHTTPRequestOperationManager.h"
开始解析数据:JSON方式获取数据
//利用第三方AFNetWorking解析数据 - (void)stringWithFormat:(NSString *)url { AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; // 网络访问是异步的,回调是主线程的,因此程序员不用管在主线程更新UI的事情 __weak NewsTableViewController * newsTVC = self; [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSDictionary * BigDic =responseObject;//responseObject相当于data NSMutableDictionary * dic = [BigDic objectForKey:@"result"]; if (dic.count != 0) { NSMutableArray * array = [dic objectForKey:@"data"]; self.modleArray = [NSMutableArray array]; for (NSMutableDictionary * smallDic in array) { NewsModle * newmodle = [[NewsModle alloc] init]; [newmodle setValuesForKeysWithDictionary:smallDic]; [newsTVC.modleArray addObject:newmodle]; } [newsTVC.tableView reloadData]; } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }]; }
标签:
原文地址:http://www.cnblogs.com/hqz-ios/p/4590598.html