Cocoa touch 使用AFNetworking从多个URL获取JSON
我需要使用AFNetworking在UITableView上加载50多个youtube视频 我是否必须在viewdidload中多次使用AFJSONRequestOperation来下载数据 以下是我尝试过的:Cocoa touch 使用AFNetworking从多个URL获取JSON,cocoa-touch,afnetworking,Cocoa Touch,Afnetworking,我需要使用AFNetworking在UITableView上加载50多个youtube视频 我是否必须在viewdidload中多次使用AFJSONRequestOperation来下载数据 以下是我尝试过的: NSString *urlAsString = @"http://gdata.youtube.com/feeds/api/playlists/PL7CF5B0AC3B1EB1D5?v=2&alt=jsonc&max-results=50"; NSString *urlA
NSString *urlAsString = @"http://gdata.youtube.com/feeds/api/playlists/PL7CF5B0AC3B1EB1D5?v=2&alt=jsonc&max-results=50";
NSString *urlAsString2 = @"http://gdata.youtube.com/feeds/api/playlists/PL7CF5B0AC3B1EB1D5?v=2&alt=jsonc&max-results=50&start-index=51";
NSURL *url = [NSURL URLWithString:urlAsString];
NSURL *url2 = [NSURL URLWithString:urlAsString2];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLRequest *request2 = [NSURLRequest requestWithURL:url2];
//现在我不知道该怎么办
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
self.videoMetaData = [JSON valueForKeyPath:@"data.items.video"];
self.allThumbnails = [JSON valueForKeyPath:@"data.items.video.thumbnail"];
[self.tableView reloadData];
// NSLog(@" video Meta Data %@", self.videoMetaData);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
}];
[operation start];
为什么不创建一个方法并将URL传递给它呢
-(void)loadVideoFromURL:(NSURL *)url {
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// setup AFNetworking stuff
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
// call delegate or processing method on success
[self someDelegateMethod:(NSDictionary *)JSON];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
}];
[operation start];
}
如何执行多个请求来执行此操作?