使用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,idresponSEObject) {
NSDictionary* BigDic =responseObject;//responseObject相当于dataNSMutableDictionary* dic = [BigDic objectForKey:@"result"];if(dic.count !=0) {
NSMutableArray* array = [dic objectForKey:@"data"];
self.modleArray=[NSMutableArray array];for(NSMutableDictionary * smallDicinarray) {
NewsModle* newmodle =[[NewsModle alloc] init];
[newmodle setValuesForKeysWithDictionary:smallDic];
[newsTVC.modleArray addObject:newmodle];
}
[newsTVC.tableView reloadData];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
}