Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func convertToDictionary(text: String) -> [String: Any]? {
- if let data = text.data(using: .utf8) {
- do {
- return try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
- } catch {
- print(error.localizedDescription)
- }
- }
- return nil
- }
- let str = "{\"name\":\"James\"}"
- let dict = convertToDictionary(text: str)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement