我遇到了一次解析两个JSON网址的问题。 YouTube每次请求只允许50个结果,因此我想添加一个起始索引为51的秒,以继续请求。
NSString *urlAsString = @"https://gdata.youtube.com/feeds/api/playlists/PLgw1uRYia2CRvuF4Y3KLuvFSWY6lmuY8T?v=2&alt=json&max-results=50&orderby=published";
NSString *urlAsString2 = @"https://gdata.youtube.com/feeds/api/playlists/PLgw1uRYia2CTSBBNrTDjdEcswVFjPkCr9?v=2&alt=json&max-results=50&orderby=published";
结合其中两个,我尝试了这个:
NSString *finallink = [NSString stringWithFormat:@"%@,%@", urlAsString, urlAsString2];
然后用Afnetworking提出实际请求,我补充道:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:finallink parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSDictionary *feed = [[NSDictionary alloc] initWithDictionary:[responseObject valueForKey:@"feed"]];
videoArray = [NSMutableArray arrayWithArray:[feed valueForKey:@"entry"]];
[self.videoMetaData addObjectsFromArray:[videoArray valueForKeyPath:@"title.$t"]];
operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[self.videolist reloadData];
[self->activityind startAnimating];
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Videos"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
NSLog(@"Error: %@", error);
}];
由于某种原因,这不起作用。我收到这个错误:
Error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)"
可能有什么不对?!