You are right, the problem arose because of "\ n". I tried your code without "\ n" and it works fine.
I replaced "\ n" with "\\ n", and iOS seems to convert the string to a dictionary:
let value = "{\"state\":\"NY\",\"city\":\"NY\",\"postalCode\":\"22002\",\"value\":\"Fifth Avenue1\nNY NY 22002\nUSA\",\"iosIdentifier\":\"71395A78-604F-47BE-BC3C-7F932263D397\",\"street\":\"Fifth Avenue1\",\"country\":\"USA\"}" if let data = value.replacingOccurrences(of: "\n", with: "\\n").data(using: String.Encoding.utf8) { do { let a = try JSONSerialization.jsonObject(with: data, options: .mutableLeaves) as? [String: Any] NSLog("check \(a)") } catch { NSLog("ERROR \(error.localizedDescription)") } }
I got this in my journal:
check Optional(["value": Fifth Avenue1 NY NY 22002 USA, "country": USA, "city": NY, "iosIdentifier": 71395A78-604F-47BE-BC3C-7F932263D397, "street": Fifth Avenue1, "postalCode": 22002, "state": NY])
source share