标签:
首先得下载AFNetworking库文件,下载时得首先弄清楚,你将要开发的软件兼容的最低版本是多少。AFNetworking 2.0或者之后的版本需要xcode5.0版本并且只能为IOS6或更高的手机系统上运行,如果开发MAC程序,那么2.0版本只能在MAC OS X 10.8或者更高的版本上运行。
接下来就是在头文件要引入
#import "AFNetworking.h"
然后
- (void)viewDidLoad {
NSString *urlString = [NSString stringWithFormat:@"http://baobab.wandoujia.com/api/v1/feed.bak?num=10&date=%f",[self getdate]];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *html = operation.responseString;
NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
//自己解析的话就在这里开始解析自己的内容就可以了
self.dataArr = [NSMutableArray new];
self.videoArray = [NSMutableArray new];
for (NSDictionary *dailyList in dict[@"dailyList"])
{
NSString *key = dailyList[@"date"];
NSMutableArray *tempArr = [NSMutableArray new];
for (NSDictionary *videoModel in dailyList[@"videoList"]) {
FZMenuModel *model = [[FZMenuModel alloc]init];
[model setValuesForKeysWithDictionary:videoModel];
[tempArr addObject:model];
}
[self.keysArr addObject:key];
[self.datadit setValue:tempArr forKey:key];
}
[self.keysArr sortUsingSelector:@selector(compare:)];
//结束解析
//刷新(一个是在controller里面自己定义的View,另一个是在自己定义的View里面又定义的一个tableview)
[self.fzmenuview.maintableview reloadData];
NSLog(@"%@",dict);
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"发生错误!%@",error);
}];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperation:operation];
}
//时间供上面网址调用
-(NSTimeInterval )getdate{
NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
NSTimeInterval a = [dat timeIntervalSince1970]* 1000;
return a;
}
标签:
原文地址:http://www.cnblogs.com/FZP5/p/4964149.html