2013-07-08 109 views
0

我目前正在使用YouTube API V2,並在收集視頻說明時收到不正確的數據。用XML快速修復?

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

我的代碼,它在你正在尋找didStartElement(其中初始化currentNodeContent)不匹配的元素名稱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; 
    } 
} 

回答

1

元素的名稱,你正在使用您的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]; 
}