0

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?

2
  • It may just be me, but that doesn't look like json. What code have you tried and what error message, or other undesirable behavior did you encounter? Commented Nov 21, 2017 at 4:12
  • Yes, it is JSON :) There was no error, I was trying to put url to webview and then get html instead of make request and then cast response to dictionary and get html. Commented Nov 21, 2017 at 9:37

1 Answer 1

1

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)
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I didn't even suspect that it will decode it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.