title: Parse json object from response inside WKWebView (Swift, iOS)
body: <p>I'm trying to receive json object from request inside <code>WKWebView</code>. For now I can only get html string from body, but it wrapped in some tags (like <code>&lt;pre&gt;</code>). How I can do it not using any third part libs? And also get body directly from response?</p>
  
  <p>My code demonstrate what I have now and it doesn't provide me what I need. I'm using delegate methods of <code>WKNavigationDelegate</code> and <code>evaluateJavaScript</code> method to get inner <code>htmlText</code> of body </p>
  
  <pre><code>func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!){
          webView.evaluateJavaScript("document.body.innerHTML") { (anyObject, error) in
              guard let htmlStr = anyObject as? String else {
                  return 
              }
              let data: Data = htmlStr.data(using: .utf8)!
              do {
                  let jsObj = try JSONSerialization.jsonObject(with: data, options: .init(rawValue: 0))
                  if let jsonObjDict = jsObj as? Dictionary&lt;String, Any&gt; {
                      let threeDSResponse = ThreeDSResponse(dict: jsonObjDict)
                      print(threeDSResponse)
                  }
              } catch _ {
                  print("having trouble converting it to a dictionary")
              }
          }
      }
  </code></pre>
  
  <p>Now I receive htmlStr as</p>
  
  <blockquote>
    <p>"{\"id\":68324947,\"is_test\":false,\"status\":2,\"status_description\":\"055
    - Invalid transaction\"}"</p>
  </blockquote>
  
  <p>and want to get it directly as json(parse it) from </p>
  
  <blockquote>
    <p>{\"id\":68324947,\"is_test\":false,\"status\":2,\"status_description\":\"055
    - Invalid transaction\"}</p>
  </blockquote>
  
  <p>also I can't use 3part libs and should make as much pure as It can be.</p>