Issue
I am currently working on this app that is integrated to a wordpress website. App Fetches JSON data and displays in TextView.
The am facing a problem with the HTML characters. The Wordpress website adds HTML codes such as <div><img>
and when it displays in the app it doesn't decode.
Is there a way of decoding HTML characters?
I am currently using below codes:
descTextView.text = NewsContentViewController.newsDetail.desc
Solution
Try using NSAttributedString
like so,
let str = NewsContentViewController.newsDetail.desc
if let data = str.data(using: .utf8) {
do {
let attrStr = try NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)
descTextView.attributedText = attrStr
print(attrStr)
} catch {
print(error)
}
}
In the above code, do handle if NewsContentViewController.newsDetail.desc
is optional String
.
Answered By - PGDev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.