【问题标题】:Unable to retrieve data in string无法检索字符串中的数据
【发布时间】:2010-07-29 06:26:07
【问题描述】:
self.pdfPath = [[NSBundle mainBundle] pathForResource:@"iPhone_SDK_License" ofType:@"pdf"];
NSData *htmlData = [NSData dataWithContentsOfFile:pdfPath];
NSString *htmlstr = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];

它在 htmlstr 中显示为 nil,所以需要一些帮助。

【问题讨论】:

  • 你需要多调试一下。 pdfPath 是零吗? htmlData 是 nil 吗?

标签: iphone objective-c nsstring


【解决方案1】:

pdf 不是 html 文件,因此我假设 initWithData:encoding: 无法理解数据,因此失败。

使用stringWithContentsOfURL:encoding:error:查看错误详情。

【讨论】:

  • 它再次显示垃圾值所以请找到我的代码如下 code self.pdfPath = [[NSBundle mainBundle] pathForResource:@"iPhone_SDK_License" ofType:@"pdf"]; self.pdfUrl = [NSURL fileURLWithPath:pdfPath]; [webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]]; NSString *myString = [NSString stringWithContentsOfURL:pdfUrl]; [fliteEngine speakText:myString]; NSLog(@"myString %@", myString);
  • pdf 编码我应该使用什么编码,因为它显示错误
  • pdf os 是一种定义的格式,包括索引而不仅仅是文本,因此简单的读取和编码将不起作用en.wikipedia.org/wiki/Portable_Document_Format
  • @Umaid:PDF 是二进制格式。其中一些是文本,一些是图像,一些是压缩数据。您绝对没有希望将 PDF 转换为文本字符串。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 2019-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多