Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. func convertToDictionary(text: String) -> [String: Any]? {
  2. if let data = text.data(using: .utf8) {
  3. do {
  4. return try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
  5. } catch {
  6. print(error.localizedDescription)
  7. }
  8. }
  9. return nil
  10. }
  11.  
  12. let str = "{\"name\":\"James\"}"
  13.  
  14. let dict = convertToDictionary(text: str)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement