【问题标题】:How do decode html data in ios?如何在ios中解码html数据?
【发布时间】:2017-03-21 06:27:13
【问题描述】:

我有表格中的数据:

%3Cp%3E%3Cstrong%3Ee-AWB+and+e

我必须对此进行解码并显示在 Webview/UILabel 中!

我已经尝试过 - URL Decoding,但它不适合我

【问题讨论】:

  • 您希望该字符串在解码后得到什么?
  • 将其作为字符串,并将特殊字符替换为相关字符以制作正确的数据。
  • @AllanPoole 我想要这种形式的结果 -

    e-AWB 和 e....

  • @AkshayYerneni 检查此stackoverflow.com/questions/1105169/…
  • 尝试使用带有NSHTMLTextDocumentType属性的原生NSAttributedString

标签: html ios objective-c decoding


【解决方案1】:

使用这个 -

- (NSString *)URLDecode:(NSString *)htmlString
{
    NSString *decodedURL = [htmlString stringByReplacingOccurrencesOfString:@"+" withString:@" "];
    decodedURL = [decodedURL stringByRemovingPercentEncoding];
    return decodedURL;
}

在这里你得到输出 - <p><strong>e-AWB and e

【讨论】:

  • 很高兴为您提供帮助。
  • 嗯,你能再帮忙解决一个问题吗?如何在 webview 中显示这些解码数据?
  • 我在尝试同样的事情,webview 中没有显示内容:/
  • 我只是在尝试您的解决方案。嗯,它仍然没有在 webview 中显示任何数据。传递 URL - website.com 需要什么?
  • 好的。我试过了,还是不行:/无论如何,感谢您帮助进行 html 解码!我会想办法显示数据。我会尽快更新答案
猜你喜欢
  • 2021-04-16
  • 2013-05-10
  • 2023-04-03
  • 2013-04-11
  • 2014-08-13
  • 1970-01-01
  • 2018-11-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多