iphonesdk中的HTML解析
我正在使用git中的hpple解析HTML。它工作得很好。但是当我得到解析后的NSString时,我发现在这个字符串中有双倒逗号(“)和单(”)替换为其他符号,如,Äô。如何获得正确的字符串?我已尝试替换这些字符,但无效。检查您的编码;底线是您可能获得UTF-8中的HTML和ISO-8859-1中的字符串。查看此链接它解决了我的问题iphonesdk中的HTML解析,iphone,html,parsing,character-encoding,html-parsing,Iphone,Html,Parsing,Character Encoding,Html Parsing,我正在使用git中的hpple解析HTML。它工作得很好。但是当我得到解析后的NSString时,我发现在这个字符串中有双倒逗号(“)和单(”)替换为其他符号,如,Äô。如何获得正确的字符串?我已尝试替换这些字符,但无效。检查您的编码;底线是您可能获得UTF-8中的HTML和ISO-8859-1中的字符串。查看此链接它解决了我的问题 https://github.com/mwaterfall/MWFeedParser 下面是添加代码的步骤 Add all the classes,except
https://github.com/mwaterfall/MWFeedParser
下面是添加代码的步骤
Add all the classes,except detailtableviewcontroller and Rootviewcontroller from the code you downloaded from the link. Then add #import "MWFeedParser.h" in your.h file where you are parsing .Then add // Parsing
MWFeedParser *feedParser;
NSMutableArray *parsedItems;
// Displaying
NSArray *itemsToDisplay;
NSDateFormatter *formatter;and /***mwfeed (*/
@property (nonatomic, retain) NSArray *itemsToDisplay;
/*------------*/
Then in .m add the codeformatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterShortStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
parsedItems = [[NSMutableArray alloc] init];
self.itemsToDisplay = [NSArray array];
// Parse
NSURL *feedURL = [NSURL URLWithString:@"http://feeds.feedburner.com/yummydietfood?format=xml"];
feedParser = [[MWFeedParser alloc] initWithFeedURL:feedURL];
feedParser.delegate = self;
feedParser.feedParseType = ParseTypeFull; // Parse feed info and all items
feedParser.connectionType = ConnectionTypeAsynchronously;
[feedParser parse];
#pragma mark -
#pragma mark MWFeedParserDelegate
- (void)feedParserDidStart:(MWFeedParser *)parser {
//[UIApplication sharedApplication].networkActivityIndicatorVisible=YES;
NSLog(@"Started Parsing: %@", parser.url);
}
- (void)feedParser:(MWFeedParser *)parser didParseFeedInfo:(MWFeedInfo *)info {
NSLog(@"Parsed Feed Info: “%@”", info.title);
//self.title = info.title;
}
- (void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item {
NSLog(@"Parsed Feed Item: “%@”", item.title);
if (item) [parsedItems addObject:item];
}
- (void)feedParserDidFinish:(MWFeedParser *)parser {
NSLog(@"Finished Parsing%@", (parser.stopped ? @" (Stopped)" : @""));
self.itemsToDisplay = [parsedItems sortedArrayUsingDescriptors:
[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"date"
ascending:NO] autorelease]]];
[UIApplication sharedApplication].networkActivityIndicatorVisible=YES;
//[self performSelector:@selector(loadData)];
[self performSelector:@selector(loadDataWithOperation)];
}
- (void)feedParser:(MWFeedParser *)parser didFailWithError:(NSError *)error {
NSLog(@"Finished Parsing With Error: %@", error);
UIAlertView *erroralert = [[UIAlertView alloc]initWithTitle:@"Error!" message:@"Problem connecting server, try again in few minutes" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[erroralert show];
[erroralert release];
self.itemsToDisplay = [NSArray array];
[parsedItems removeAllObjects];
self.tbl.userInteractionEnabled = YES;
[self.tbl reloadData];
}
在这里,您需要被称为行代码的解析器解析的数据
if (item) {
NSString *itemTitle = item.title ? [item.title stringByConvertingHTMLToPlainText] : @"[No Title]";
lbl.text = itemTitle;
}
else {
lbl.text=@"No Title";
}
我使用的是:NSData*htmlData=[[NSString stringWithContentsOfURL:[NSURL URLWithString:@“dataUsingEncoding:NSUTF8StringEncoding];当我使用Hpple时,我的应用程序正在不断终止。是的,谢谢Aman。它很好。它正在使用我的URL。你能给我一些简单的步骤将其添加到我的项目中吗?目前我正在使用Hpple,但应用程序在不显示任何警告或异常的情况下不断终止。