ios - 使用来自 YouTube 用户上传的 JSON 数据填充表格 View - iOS
<p><p>我正在努力使用来自 <code>Youtube (V 2.1)</code> 的 <code>JSON</code> 数据填充表格 View ,该数据已被解析(在控制台中记录输出)</p >
<p>每次我加载 Table View Controller 时,都没有填充任何内容。我什至创建了一个“视频”类(NSObject)。我正在努力理解我做错了什么。 </p>
<p>以下是我的代码:
视频.h</p>
<pre><code>#import <Foundation/Foundation.h>
@interface Video : NSObject
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *description;
@property (nonatomic, strong) NSString *thumbnail;
@property (nonatomic, strong) NSString *uploadedDate;
@property (nonatomic, strong) NSURL *url;
// Designated Initializer
- (id) initWithTitle:(NSString *)title;
+ (id) videoWithTitle:(NSString *)title;
- (NSURL *) thumbnailURL;
- (NSString *) formattedDate;
@end
</code></pre>
<p>视频.m</p>
<pre><code>import "Video.h"
@implementation Video
- (id) initWithTitle:(NSString *)title {
self = ;
if ( self ){
self.title = title;
self.thumbnail = nil;
}
return self;
}
+ (id) videoWithTitle:(NSString *)title {
return [ initWithTitle:title];
}
- (NSURL *) thumbnailURL {
// NSLog(@"%@",);
return ;
}
- (NSString *) formattedDate {
NSDateFormatter *dateFormatter = [ init];
;
NSDate *tempDate = ;
;
return ;
}
@end
</code></pre>
<p>Table View Controller 实现文件(我要填充的那个)</p>
<pre><code>#import "FilmyViewController.h"
#import "Video.h"
@interface FilmyViewController ()
@end
@implementation FilmyViewController
- (void)viewDidLoad
{
;
NSURL *videoURL = ;
NSData *jsonData = ;
NSError *error = nil;
NSDictionary *dataDictionary = ;
NSLog(@"%@",dataDictionary);
self.videoArray = ;
NSArray *videosArray = ;
for (NSDictionary *vDictionary in videosArray) {
Video *video = ];
video.title = ;
video.description = ;
video.uploadedDate = ;
video.url = ];
;
}
}
- (void)didReceiveMemoryWarning
{
;
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = ;
Video *video = ;
// Configure the cell...
cell.textLabel.text = video.title;
cell.textLabel.text = video.description;
return cell;
}
/*
#pragma mark - Navigation
// In a story board-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using .
// Pass the selected object to the new view controller.
}
*/
@end
</code></pre>
<p>这里是 <a href="http://gdata.youtube.com/feeds/api/users/OrtoForum/uploads?v=2&alt=jsonc" rel="noreferrer noopener nofollow">JSON which I'm trying to extract from</a> .</p>
<p>我寻找了类似的主题,但没有得到任何合适的解决方案。
研究 <a href="https://stackoverflow.com/questions/11814930/youtube-video-feed-in-json-into-table-view" rel="noreferrer noopener nofollow">Link-one</a>和 <a href="https://github.com/weed/p120805_YouTubeJsonParse" rel="noreferrer noopener nofollow">Link-two</a>是我一直试图遵循的。</p>
<p>如果有更好的方法,请告诉我。
我在这里错过了什么?</p>
<p><strong>解决方案</strong></p>
<p>改变了</p>
<pre><code>NSArray *videosArray = ;
</code></pre>
<p>到:</p>
<pre><code>NSArray *videosArray = dataDictionary[@"data"][@"items"];
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>改变</p>
<p><code>NSArray *videosArray = ;</code></p>
<p>到</p>
<pre><code>NSArray *videosArray = dataDictionary[@"data"][@"items"];
</code></pre>
<p>您的 items 数组位于第二级:<strong>rootJSON -> data -> items</strong></p></p>
<p style="font-size: 20px;">关于ios - 使用来自 YouTube 用户上传的 JSON 数据填充表格 View- iOS,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/20635801/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/20635801/
</a>
</p>
页:
[1]