xcode 如何将 HTML NSData 转换为 NSString?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6719890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I convert HTML NSData to an NSString?
提问by Carter Pape
I'm using [NSData dataWithContentsOfURL:]
to create two NSData instances and I want to compare these instances to gauge how different they are. Since they're both from the same website, using a string to find what is different will help me highlight the actual element(s) that has (have) changed. Is it possible to change this data to a string to find the difference?
我正在使用[NSData dataWithContentsOfURL:]
创建两个 NSData 实例,我想比较这些实例以衡量它们的不同之处。由于它们都来自同一个网站,因此使用字符串查找不同之处将有助于我突出显示已更改的实际元素。是否可以将此数据更改为字符串以查找差异?
回答by VenoMKO
Try initWithData:encoding:
method of NSString to create string with your data.
尝试initWithData:encoding:
使用 NSString 方法用您的数据创建字符串。
Exmp: NSString *str = [[NSString alloc] initWithData:someData encoding:NSUTF8StringEncoding]
例如: NSString *str = [[NSString alloc] initWithData:someData encoding:NSUTF8StringEncoding]
回答by Pencho Ilchev
Why don't you use NSString stringWithContentsOfURL:encoding:error:
为什么不使用 NSString stringWithContentsOfURL:encoding:error: