我正在尝试解析RSS Feed。事情一直很好,但是最近它在解析pubDate元素时开始变得混乱。这是我的解码代码,以及两个NSLog,第一个日志来自RSS Feed的pubDate元素,第二个日志是我尝试将其转换为NSDate时。由于某种原因,这种情况一直很好,直到今天下午才结束。
- (void)parseRss:(GDataXMLElement *)rootElement entries:(NSMutableArray *)entries {
NSArray *channels = [rootElement elementsForName:@"channel"];
for (GDataXMLElement *channel in channels) {
NSString *blogTitle = [channel valueForChild:@"title"];
NSArray *items = [channel elementsForName:@"item"];
for (GDataXMLElement *item in items) {
NSString *articleTitle = [item valueForChild:@"title"];
NSString *articleUrl = [item valueForChild:@"guid"];
NSString *articleDateString = [item valueForChild:@"pubDate"];
NSLog(@"frompubdate%@", articleDateString);
NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC822];
NSLog(@"fromdate%@", articleDate);
NSString *articleImage = [item valueForChild:@"description"];
NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
NSString *dateofarticle = [dateFormatter stringFromDate:articleDate];
RSSEntry *entry = [[[RSSEntry alloc] initWithBlogTitle:blogTitle articleTitle:articleTitle articleUrl:articleUrl articleDate:articleDate articleImage:bodyoftext] autorelease];
[entries addObject:entry];
}
}
}
Sun,20120年10月28日:30:00 CST
无法解析RFC822日期:“太阳报,20120年10月28日:30:00 CST”格式可能无效。