2011-03-10 50 views
1

我想解析html ..所以我已经找到了一些示例代码:http://blog.objectgraph.com/index.php/2010/02/24/parsing-html-iphone-development/ 它使用hpple来解析html ...但有一个问题,这个应用程序不断崩溃的原因很可能是这条线在这里:hpple html解析iphone sdk帮助?

NSURL *url = [NSURL URLWithString: @"http://www.objectgraph.com/contact.html"]; 
NSString *contents = [NSString stringWithContentsOfURL:url]; 
NSData *htmlData = [contents dataUsingEncoding:NSUTF8StringEncoding]; 

的Xcode给我警告stringWithCOntentsofVariable已被弃用..

所以任何人都可以帮我解决这个问题....通过展示什么样的代码应该怎么改?

感谢

回答

3

30秒the documentation显示:

返回从给定的URL指定的文件中读取数据创建一个字符串。 (不推荐使用在Mac OS X 10.4。使用stringWithContentsOfURL:encoding:error:stringWithContentsOfURL:usedEncoding:error:代替。)

因此,它看起来像你应该使用stringWithContentsOfURL:encoding:errorstringWithContentsOfURL:usedEncoding:error:代替。

就像文档说的那样。