Forked from stevenojo/jsonString method for Dictionary
Created
July 16, 2019 07:56
-
-
Save EndLess728/2de57dbce8d440ecac591ca36e848db3 to your computer and use it in GitHub Desktop.
Convert Dictionary to a JSON string in swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Dictionary { | |
func jsonString() -> NSString? { | |
let jsonData = try? JSONSerialization.data(withJSONObject: self, options: []) | |
guard jsonData != nil else {return nil} | |
let jsonString = String(data: jsonData!, encoding: .utf8) | |
guard jsonString != nil else {return nil} | |
return jsonString! as NSString | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment