How to decode HTML using Swift?

305 views Asked by At

How to decode HTML from an API response like this JSON string to get clear HTML to put it into webView?

<head lang="pl">
<meta charset="UTF-8">
<meta name='viewport' content='width=device-width,initial-scale=1.0'>
<style type="text/css" media="screen">

Fully converted HTML: https://pastebin.com/CKhXzYup

I know that firstly I have to cast JSON to dictionary, and then?

1

There are 1 answers

1
Santhosh R On BEST ANSWER

Once you get the html string from the dictionary, load it into WKWebView. Eg.:

if let htmlString = yourDict["render_page"] as? String{
   let webView = WKWebView(frame: self.view.bounds)
   self.view.addSubview(webView)
   webView.loadHTMLString(htmlString, baseURL: nil)
}