Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa touch 使用AFNetworking从多个URL获取JSON_Cocoa Touch_Afnetworking - Fatal编程技术网

Cocoa touch 使用AFNetworking从多个URL获取JSON

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

我需要使用AFNetworking在UITableView上加载50多个youtube视频

我是否必须在viewdidload中多次使用AFJSONRequestOperation来下载数据

以下是我尝试过的:

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];

}

如何执行多个请求来执行此操作?