0

I get response from server in wincp1251 and restkit returns nil to my mapped object strings. I know restKit have a property defaultHTTPEncoding in RKClient(https://github.com/RestKit/RestKit/commit/0ead8a922219ec42ec6dae6ebe59139a1fd589ae), how can I use this and can it helps me?

Wain
  • 118,658
  • 15
  • 128
  • 151

1 Answers1

0

I'm assuming that your server is returning JSON. If this is the case then the server needs to be updated because it isn't conformant to the JSON spec. Specifically:

  1. Encoding

    JSON text SHALL be encoded in Unicode. The default encoding is UTF-8.

An important point to note is that RestKit doesn't unpack the response into a string, because the JSON deserialisation takes a data object (NSJSONSerialization). And again, the spec states:

The data must be in one of the 5 supported encodings listed in the JSON specification: UTF-8, UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE. The data may or may not have a BOM. The most efficient encoding to use for parsing is UTF-8, so if you have a choice in encoding the data passed to this method, use UTF-8.

So to handle your server response, if you can't change it, you'll need to handle the download yourself, convert the data to the appropriate encoding, unpack the JSON, and then create a mapping operation to use that.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • but if I have xml response, not json? – Vasili Krasnouski Apr 07 '16 at 08:56
  • you should really add that information to the question, but i guess the problem is the same and the serialisation is throwing an unknown / unsupported encoding error. you should really download and decode the data separately and then map it once its in a better format. – Wain Apr 07 '16 at 09:53
  • thank you very much, it's better explain, you save my day! – Vasili Krasnouski Apr 07 '16 at 10:34
  • no problem. in future just try to add a bit more information about what you're doing. don't forget to vote and mark answers too :) – Wain Apr 07 '16 at 11:00