AFNetworking serializes forward slash making the JSON payload invalid AFNetworking serializes forward slash making the JSON payload invalid json json

AFNetworking serializes forward slash making the JSON payload invalid


This is know problem. It actually behaves as designed (see https://stackoverflow.com/a/20448342/669586).

There are 3 possible solution:

  1. Make your server aware of the possibility that strings can be escaped. In general, this is the best solution.

  2. Use a different JSON encoder (e.g. SBJson) and encode the object to NSData instead of using AFNetworking default serializer.

  3. Encode using NSJSONSerialization and then convert the resulting data to a NSString (using NSUTF8StringEncoding), sanitize it and convert it back to NSData. Again, you have to do that before giving the object to AFNetworking.

The best way to implement 2 or 3 is setting a custom requestSerializer on the AFHTTPSessionManager instance. For example, see this answer for an example of implementing 3 (note it's in Swift).