let dic = ["2": "B", "1": "A", "3": "C"] do { let jsonData = try JSONSerialization.data(withJSONObject: dic, options: .prettyPrinted) // here "jsonData" is the dictionary encoded in JSON data let decoded = try JSONSerialization.jsonObject(with: jsonData, options: []) // here "decoded" is of type `Any`, decoded from JSON data // you can now cast it with the right type if let dictFromJSON = decoded as? [String:String] { // use dictFromJSON } } catch { print(error.localizedDescription) }
