admin管理员组文章数量:1122846
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. ‘. All other characters seem fine. Any Ideas to that?
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. ‘. All other characters seem fine. Any Ideas to that?
Share Improve this question asked Aug 20, 2018 at 13:56 MartinMartin 112 bronze badges 2- How are you sending from WP to your iOS App? Did you see this response? wordpress.stackexchange.com/a/303881/137650 – Jorge Casariego Commented Aug 20, 2018 at 14:16
- Thanks for looking into this. The IOS App makes simple Rest API calls. Such as: somedomain.com/wp-json/wp/v2/news/7108. When I open the link in Firefox it displays the JSON formated in a readable way. And it also displays the ‘ for a ' in a title. – Martin Commented Aug 20, 2018 at 14:23
1 Answer
Reset to default 0I'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‘House --> WordPress'House
- 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 ?? ""
}
}
- Use the extension
`
let htmlString = "WordPress‘House"
print("String is: ", textFromWP.html2String)
本文标签: Rest API encoding of double quotes
版权声明:本文标题:Rest API encoding of double quotes 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736286968a1927781.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论