YouTube Video Feed in JSON into table view

2019-06-11 22:15发布

How to get the youtube videos in JSON formate for list in UITableView. I need At a time 20 feeds to be listed and in show more button then next 20 results needed to display.

I am expecting the exact url to get the feeds in both case.

Now i am trying Url i give as example.

http://gdata.youtube.com/feeds/api/videos?start-index=11&max-results=20&v=2&alt=jsonc
http://gdata.youtube.com/feeds/api/videos?start-index=2&max-results=20&v=2&alt=jsonc

Thanks in Advance

1条回答
你好瞎i
2楼-- · 2019-06-11 22:30

Below code parse YouTube JSON to table view.

ss

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    if (indexPath.row < [[_JSON valueForKeyPath:@"data.items.title"] count]) {
        cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
        cell.textLabel.text = 
        [[_JSON valueForKeyPath:@"data.items.title"] objectAtIndex:indexPath.row];
        cell.detailTextLabel.text =
        [[_JSON valueForKeyPath:@"data.items.description"] objectAtIndex:indexPath.row];
    }
    return cell;
}

The code to get JSON is below:

- (IBAction)refresh:(id)sender {
    NSURL *url = [NSURL URLWithString:kStrJsonURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id getJSON) {
        _JSON = getJSON;
        NSLog(@"%@", _JSON);
        [self.tableView reloadData];
    } failure:nil];
    [operation start];        
}

You should read getting started about AFNetworking:

https://github.com/AFNetworking/AFNetworking/wiki/Getting-Started-with-AFNetworking

You can download sample project from GitHub and just run it:

https://github.com/weed/p120805_YouTubeJsonParse

查看更多
登录 后发表回答