NSJSONSerialization serialization of a string containing forward slashes / and HTML is escaped incorrectly

后端 未结 3 402
挽巷
挽巷 2020-12-10 05:01

I am trying to convert some simple HTML into a string value in a JSON object and I\'m having trouble getting the string encoding to not escape the string in NSJSONSerializat

3条回答
  •  天涯浪人
    2020-12-10 05:47

    iOS 13 only: If you're not worried about producing invalid HTML sequences (as described in this answer), you can disable forward-slash escaping by passing the option NSJSONWritingWithoutEscapingSlashes to the serializer.

    Example:

    jsonData = [NSJSONSerialization dataWithJSONObject:batchUpdates
                                               options:NSJSONWritingWithoutEscapingSlashes
                                                 error:nil];
    

提交回复
热议问题