fix: current code wasn't able to parse JSON responses with encoding other than UTF-8, UTF-16, UTF-32 #876

wants to merge 2 commits into from

3 participants


First, thanks for the great library :-)
I think i found a bug in parsing JSON responses using the response encoding.
Afaik this is done in 2 steps, first parsing the responseString into a unicode using the response encoding.
Second parsing the JSON out of the responseString unicode.
According to the Apple spec (, data given to [NSJSONSerialization JSONObjectWithData:..] must be encoded with one of UTF-8, UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE.
Anything else won't work afaik.
The current code is using the response encoding for building the NSData from the responseString, so parsing JSON from an URI which uses an encoding other than the 5 listed above will fail (e.g. ISO-8859-1).
The responseString is already a unicode, so I think hardcoding the encoding here to UTF-8 won't harm anything and fixes problems when the response encoding is not one of the by NSJSONSerialization supported ones.


Seems like this might be an alternate solution to #862


This appears to be the right solution. Thanks for the patch. This has been merged in with 205a8aa.

@mattt mattt closed this Apr 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment