How to restore html tags after the app passes the http acl for iOS, and escape html tags for ios

Source: Internet
Author: User

How to restore html tags after the app passes the http acl for iOS, and escape html tags for ios

Recently, I used swift to build a small project in a company. I encountered a problem: the tags in html text obtained through APIs have been escaped,

& Lt; p class = & quot; MsoNormal & quot; align = & quot; left & quot; style = & quot; vertical-align: baseline; background: white; & quot; & gt; \ n \ t & lt; br/& gt; \ n & lt;/p & gt; \ n & lt; p class = & quot; MsoNormal & quot; align = & quot; left & quot; style = & quot; vertical-align: baseline; background: white; & quot; & gt; \ n \ t & lt; B & gt; (original title: required for new car owners! Required for car maintenance and repair & lt;/B & gt; & lt; B & gt; 20 & lt;/B & gt; & lt; B & gt; large & lt;/B & gt; & lt; B & gt; "& lt;/B & gt; & lt; B & gt; iron & lt; /B & gt; & lt; B & gt; ") & lt;/B & gt; \ n & lt;/p & gt; \ n & lt; p class = & quot; MsoNormal & quot; align = & quot; left & quot; style = & quot; vertical-align: baseline; background: white; & quot; & gt; \ n \ t2016-06-13 \ n & lt;/p & gt; \ n & lt; p class = & quot; MsoNormal & quot; align = & quot; left & quot; style = & quot; vertical-align: baseline; background: white; & quot; & gt; \ n \ t & lt; B & gt; 1. & lt;/B & gt; & lt; B & gt; the most important of the two guarantees for a new car & lt;/B & gt; \ n & lt;/p & gt; \ n & lt; p class = & quot; MsoNormal & quot; align = & quot; left & quot; style = & quot; vertical ....................................... ......

Directly call webview. loadHTMLString (content !, BaseURL: nil) will be shown in the figure below in webview

 

Finally, the omnipotent github found a String extension.

import Foundationimport UIKitextension String {    var htmlToString:String {        return try!  NSAttributedString(data: dataUsingEncoding(NSUTF8StringEncoding)!, options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute:NSUTF8StringEncoding], documentAttributes: nil).string    }}

Perfect solution

Mark here

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.