XML快速修复



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

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

这是我想得到的字符串

我们能为所有伟大的目标点5000个赞吗?:)http://www.facebook.com/GudjonDanielYThttps://twitter.com/GudjonDaniel

但我有一个

GudjonDanielhttp://gdata.youtube.com/feeds/api/users/GudjonDanielkM0YirXKa4Lb7MsgqHWiMwEntertainmentgudjondanielCan我们所有伟大的进球都获得了5000个赞?:)http://www.facebook.com/GudjonDanielYThttps://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;
    }
}

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

因此,你的行说:

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

可能应该说:

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

相关内容

  • 没有找到相关文章

最新更新