Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let jsonObject: [String: Any] = [
- "firstname": "aaa",
- "lastname": "sss",
- "email": "my_email",
- "nickname": "ddd",
- "password": "123",
- "username": "qqq"
- ]
- do {
- let jsonData = try JSONSerialization.data(withJSONObject: jsonObject, 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] {
- print(dictFromJSON)
- }
- } catch {
- print(error.localizedDescription)
- }
Advertisement
Add Comment
Please, Sign In to add comment