I’m trying to figure out why special characters in a JSON feed (that looks completely fine when viewed in a browser) will break when used in my Android code. Characters with accent marks, ellipsis characters, curly quote characters and so on are replaced by other characters–perhaps translating it from UTF-8 down to ASCII? I’m not sure. I’m using a GET request to pull JSON data from a server, parsing it, storing it in a database, then using Html.fromHtml() and placing the contents in a TextView.
Share
After much experimentation, I narrowed down possibilities until I discovered the problem is with the Ignition HTTP libraries (https://github.com/kaeppler/ignition). Specifically, with ignitedHttpResponse.getResponseBodyAsString()
Although that’s a handy shortcut, that one line results in the broken characters. Instead, I now use:
Edit: Adding more detail
Here is a minimum test case to reproduce the issue.
In the log:
Update: either I’m crazy, or the problem only occurs in the clients’ production feed, not their development feed, although the contents look identical when viewed in a browser–showing “Texas’”. So perhaps there’s some wonky server configuration required to cause this issue… but still, the fix for this issue when it occurs is as I outlined. I do not recommend using response.getResponseBodyAsString();