How to encode and then decode to JSON, to escape meantime the special character?
I have now this code:
let o5: [String: Any] = ..
let o6 = try JSONSerialization.data(withJSONObject: o5, options: JSONSerialization.WritingOptions.prettyPrinted)
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601
decoder.keyDecodingStrategy = .useDefaultKeys
let o7 = try decoder.decode(Organization.self, from: o6)
I would do following text replacement: /
-> \/
, new line -> \n
, "
-> \"
.
Recently I have unfortunatelly unescaped special characters in my DB.