1

我目前正在使用 Youtube API 并从频道获取结果。但是,当我尝试获取描述时,它总是停在最后&,我只得到描述的一部分。

这是我从 http://gdata.youtube.com/feeds/api/users/smosh/uploads?max-results=1获取 XML 信息的网站

- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if ([elementname isEqualToString:@"content"])
    {
        currentFeed.description = currentNodeContent;
    }

    if ([elementname isEqualToString:@"entry"])
    {
        [self.feeds addObject:currentFeed];
        currentFeed = nil;
        currentNodeContent = nil;
    }
}

内容正在从视频中获取描述。

但是我只得到这些结果


Wardrobe: Paula Barkley Asst. Editor: Justin Dailey | Color: Pretty Moving Pictures BTS: Phil Mohr | Key PA: Brad Westerbeck

------------------------------------ Hey it's our very own website: http://smosh.com Oh and our Facebook page: http://facebook.com/smosh Want to know when we're filming and/or pooping? Now you can:http://twitter.com/smosh Guess we should have a Google+ Page, too: http://google.com/+smosh

当这是整个描述时:

Bloopers & ALTERNATE SCENES: http://smo.sh/FriendsXTRAS DOWNLOAD OUR NEW GAME: http://smo.sh/HeadEsploder

Ian and Anthony need some new friends.

Cast: Anthony as Himself Ian as Himself Ryan Todd as Stevie Ryan Cicak and Robert Haley as the New Neighbors

Written by: Anthony Padilla, Ian Hecox, & Ryan Finnerty Produced & Directed by: Anthony Padilla, Ian Hecox, & Ryan Todd Edited by: Anthony Padilla & Michael Barryte Post Supervision by: Ian Hecox & Ryan Finnerty

AD: Frank Cosgriff | DP: John Alexander Jimenez Asst. Camera: Shawna Smith | Sound Mixer: Palmer Taylor Gaffer: Kerry Sweeney | Grips: Jon Hooker & Lee Eisenhower Production Design: Patrick Egan | MUA & Wardrobe: Paula Barkley Asst. Editor: Justin Dailey | Color: Pretty Moving Pictures BTS: Phil Mohr | Key PA: Brad Westerbeck

------------------------------------  Hey it's our very own website: http://smosh.com Oh and our Facebook page: >http://facebook.com/smosh Want to know when we're filming and/or pooping? Now you can:http://twitter.com/smosh Guess we should have a Google+ Page, too: http://google.com/+smosh

这是我的整个班级文件

4

1 回答 1

1

您的代码假定 foundCharacters在单个调用中返回元素的整个值。这不是一个有效的假设(尤其是对于长值)。这就是为什么您只看到content标签的结尾,因为其余的值是在之前的调用中返回的foundCharacters,但是您在随后的每次调用中都丢弃了它foundCharacters

对于 long 值,事件序列是 (a) 调用didStartElement; (b) 多次调用,foundCharacters直到返回整个值;最后 (c) 调用didEndElement.

所以:

  1. 如果遇到和元素名称,则进行didStartElement初始化:currentNodeContenttitlecontent

    currentNodeContent = [[NSMutableString alloc] init];
    
  2. 然后,foundCharacters应该只附加stringcurrentNodeContent

    [currentNodeContent appendString:string];
    

    注意:确保它不会修剪字符串(如果要修剪,请在 中进行didEndElement,而不是在 中foundCharacters)。

  3. 如果元素名称是or ,则didEndElement保存它,然后它也应该设置为。currentNodeContenttitlecontentcurrentNodeContentnil

于 2013-07-07T18:04:14.383 回答