我目前正在使用YouTube API V2,并且在收集视频说明时收到的数据不正确。
This is the link where I'm getting the XML information from.
这是我想要的字符串
我们可以为所有伟大目标命中5000次吗? :) http://www.facebook.com/GudjonDanielYT https://twitter.com/GudjonDaniel
但是我得到了这个
GudjonDanielhttp://gdata.youtube.com/feeds/api/users/GudjonDanielkM0YirXKa4Lb7MsgqHWiMwEntertainmentgudjondanielCan 我们为所有伟大目标命中了5000次赞? :) http://www.facebook.com/GudjonDanielYT https://twitter.com/GudjonDaniel
我的代码,它位于media:description
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementname isEqualToString:@"title"] || [elementname isEqualToString:@"content"])
{
currentNodeContent = [[NSMutableString alloc] init];
}
else if ([elementname isEqualToString:@"entry"])
{
currentFeed = [ChanelFeeds alloc];
}
else if ([elementname isEqualToString:@"yt:duration"])
{
currentFeed.duration = [attributeDict objectForKey:@"seconds"];
}
else if ([elementname isEqualToString:@"yt:statistics"])
{
currentFeed.views = [attributeDict objectForKey:@"viewCount"];
}
else if ([elementname isEqualToString:@"gd:rating"])
{
currentFeed.rating = [attributeDict objectForKey:@"average"];
}
else if ([elementname isEqualToString:@"media:player"])
{
currentFeed.streamURL = [NSURL URLWithString:[attributeDict objectForKey:@"url"]];
}
else if ([elementname isEqualToString:@"media:thumbnail"] && !currentFeed.thumbnailURL)
{
currentFeed.thumbnailURL = [NSURL URLWithString:[attributeDict objectForKey:@"url"]];
}
}
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementname isEqualToString:@"title"])
{
currentFeed.title = currentNodeContent;
currentNodeContent = nil;
}
else if ([elementname isEqualToString:@"media:description"])
{
currentFeed.description = currentNodeContent;
currentNodeContent = nil;
}
else if ([elementname isEqualToString:@"entry"])
{
[self.feeds addObject:currentFeed];
currentFeed = nil;
currentNodeContent = nil;
}
}
答案 0 :(得分:1)
您在didStartElement
中搜索的元素名称(初始化currentNodeContent
)与您用于保存和重置currentNodeContent
的元素名称不匹配didEndElement
方法。
因此,你的行说:
if ([elementname isEqualToString:@"title"] || [elementname isEqualToString:@"content"])
{
currentNodeContent = [[NSMutableString alloc] init];
}
可能应该说:
if ([elementname isEqualToString:@"title"] || [elementname isEqualToString:@"media:description"])
{
currentNodeContent = [[NSMutableString alloc] init];
}