Swift - Parse a string which contains a URL
<p>How can parse this  string : </p>

<blockquote>
  <p><a href="http://www.ha" rel="nofollow noreferrer">http://www.ha</a>***ay.ir/pa***nt/result_false.php?error=Canceled%20By%20User</p>
</blockquote>

<p>I tried using the code given below for converting the given string to a dictionary. But I got this error : </p>

<blockquote>
  <p>The data couldn’t be read because it isn’t in the correct format.</p>
</blockquote>

<p>This is my code : </p>

<pre><code>func webViewDidFinishLoad(_ webView: UIWebView) {      
    print("finish loading")
    let yourTargetUrl = webView.request?.url?.absoluteString
    print(yourTargetUrl!)
    let parse = convertToDictionary(text: yourTargetUrl!)
}

func convertToDictionary(text: String) -&gt; [String: Any]? {
    if let data = text.data(using: .utf8) {
        do {
            return try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
        } catch {
            print(error.localizedDescription)
        }
    }
    return nil
}
</code></pre>