zoukankan      html  css  js  c++  java
  • iOS UIwebView html 字符串转换

    解析json字段是一段html串,平常解析出来都能在uiwebview上正常显示,这却出现以下状况,文本内容夹杂好多不需要显示的字符,例如:
    NSString*string =@"<span>文本内容</span>";
    这就需要处理一下再显示。
    方法如下:

     html=[self htmlEntityDecode :[dict objectForKey:@"data"]];

    -(NSString*)htmlEntityDecode:(NSString*)string
        {
            string =[string stringByReplacingOccurrencesOfString:@""" withString:@"""];
            string =[string stringByReplacingOccurrencesOfString:@"'" withString:@"'"];
            string =[string stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
            string =[string stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
            string =[string stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
           return string;
    }

    [webView_InformationloadHTMLString:html  baseURL:[NSURLURLWithString:@"http://www.maystall.com/"]];

    webView_Information.delegate=self;

    然后文本内容就正常显示了。

  • 相关阅读:
    Oracle 数据库简介
    Qt 中事件与处理
    npm常用命令总结
    自适应宽度布局
    原生js发送ajax请求
    微信调试本地环境代码
    多行文本溢出显示省略号
    清除浮动
    用JQuery动态为选中元素添加/删除类
    input中加入搜索图标
  • 原文地址:https://www.cnblogs.com/someonelikeyou/p/3578779.html
Copyright © 2011-2022 走看看