将JSON中的YouTube视频供稿放入表格视图 [英] YouTube Video Feed in JSON into table view

查看:126
本文介绍了将JSON中的YouTube视频供稿放入表格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取JSON格式的youtube视频作为UITableView中的列表.我需要一次列出20个供稿,并在显示更多按钮中,然后需要显示下20个结果.

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.

现在我正在尝试以Url为例.

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

预先感谢

推荐答案

以下代码将YouTube JSON解析为表格视图.

Below code parse YouTube JSON to table view.

- (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;
}

获取JSON的代码如下:

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

您应该阅读有关AFNetworking的入门:

You should read getting started about AFNetworking:

https://github.com/AFNetworking/AFNetworking/wiki /AFNetworking入门

您可以从GitHub下载示例项目并运行它:

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

https://github.com/weed/p120805_YouTubeJsonParse

这篇关于将JSON中的YouTube视频供稿放入表格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆