How to restore HTML tags after iOS is in transit

Source: Internet
Author: User

The recent use of Swift as a small company project has encountered the problem that the tags in the HTML text obtained through the API have been escaped,

<P class="MsoNormal"align="Left"style="Vertical-align:baseline;background:white;">\n\t<BR/>\ n</P>\ n<P class="MsoNormal"align="Left"style="Vertical-align:baseline;background:white;">\n\t<B>(Original title: New owner must see!) It is necessary to keep the car repaired by car.</b><B>20</b><B>Big</b><B>“</b><B>Iron Law</b><B>”)</b>\ n</P>\ n<P class="MsoNormal"align="Left"style="Vertical-align:baseline;background:white;">\N\T2016-06-13 19:09\n</P>\ n<P class="MsoNormal"align="Left"style="Vertical-align:baseline;background:white;">\n\t<B>1.</b><B>The new car and the two are the most important</b>\ n</P>\ n<P class="MsoNormal"align="Left"style="Vertical ..... ..... ...........................

Call WebView directly. loadHTMLString(content!, BaseURL: nil) will look like in the figure below in WebView

Finally, a string extension was found on the Magnum GitHub

Import Foundationimport uikitextension String {    var  htmltostring:string {          Returntry!  Nsattributedstring (data:datausingencoding (nsutf8stringencoding)!, options: [Nsdocumenttypedocumentattribute: Nshtmltextdocumenttype,nscharacterencodingdocumentattribute:nsutf8stringencoding], Documentattributes:nil). string     }}

Perfect solution

Mark here.

How to restore HTML tags after iOS is in transit

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.