0

我目前正在使用 YouTube API V2,但在收集视频描述时收到了不正确的数据。

这是我从中获取 XML 信息的链接。

这是我想得到的字符串

我们可以为所有伟大的目标达到 5000 个赞吗?:) http://www.facebook.com/GudjonDanielYT https://twitter.com/GudjonDaniel

但我得到了这个

GudjonDanielhttp://gdata.youtube.com/feeds/api/users/GudjonDanielkM0YirXKa4Lb7MsgqHWiMwEntertainmentgudjondaniel 我们能否为所有伟大目标获得 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;
    }
}
4

1 回答 1

1

您正在查找的元素名称didStartElement(初始化)与您currentNodeContent在方法中用于保存和重置的元素名称不匹配。currentNodeContentdidEndElement

因此,您的台词说:

if ([elementname isEqualToString:@"title"] || [elementname isEqualToString:@"content"])
{
    currentNodeContent = [[NSMutableString alloc] init];
}

大概应该说:

if ([elementname isEqualToString:@"title"] || [elementname isEqualToString:@"media:description"])
{
    currentNodeContent = [[NSMutableString alloc] init];
}
于 2013-07-08T18:12:38.063 回答