【发布时间】:2015-01-10 01:41:42
【问题描述】:
我尝试解析以下 youtube JSON,以便可以访问标题、描述等内容... https://gdata.youtube.com/feeds/api/videos?q=remedyLIVE&max-results=5&v=2&alt=jsonc&orderby=published
现在我把它放在一个字典中,它返回两个值/键对。一个用于 api,另一个用于其他所有内容。
我将在下面附上我的代码,但我知道它很接近但不太正确。谁能提供一个关于如何解析这个json的具体例子?我找不到任何关于如何做到这一点的好例子,所以如果有人可以帮助我访问这些值,那就太棒了。我花了无数个小时阅读 JSON 教程,但我仍然无法弄清楚它如何适用于我正在做的事情。谢谢!!
NSURL *youtubeURL = [NSURL URLWithString:@"https://gdata.youtube.com/feeds/api/videos?q=remedyLIVE&max-results=5&v=2&alt=jsonc&orderby=published"];
NSData *data = [NSData dataWithContentsOfURL:youtubeURL];
if (data == nil)
{
NSLog(@"data is nil");
}
else
{
NSError *error;
titleArray = [[NSMutableArray alloc]init];
videoIDArray = [[NSMutableArray alloc]init];
thumbArray = [[NSMutableArray alloc]init];
videoDictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"%@", videoDictionary);
}
}
【问题讨论】:
标签: ios objective-c json cocoa-touch youtube