Rest API encoding of double quotes

I have a standard rest API setup in WP. The results are displayed in an IOS App. Now the problem occurres, that single and double quotes and are returned in the JSON as Unicode Decimal Code: eg. #8216. All other characters seem fine. Any Ideas to that?

Topic rest-api Wordpress encoding

Category Web


I'll show here an example of how you can convert the HTML to Plain Text in Swift 4.

This example simulate that you're receiving this:

WordPress&#8216House --> WordPress'House

  1. Add this extension to convert your html code to a regular string:

`

extension Data {
    var html2AttributedString: NSAttributedString? {
        do {
            return try NSAttributedString(data: self, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil)
        } catch {
            print("error:", error)
            return  nil
        }
    }
    var html2String: String {
        return html2AttributedString?.string ?? ""
    }
}

extension String {
    var html2AttributedString: NSAttributedString? {
        return Data(utf8).html2AttributedString
    }
    var html2String: String {
        return html2AttributedString?.string ?? ""
    }
}
  1. Use the extension

`

let htmlString = "WordPress&#8216House"

print("String is: ", textFromWP.html2String)

enter image description here

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.