Created
November 29, 2018 21:26
-
-
Save ChetanBhasin/2176eacff333d9cf4c7b5b93938718b9 to your computer and use it in GitHub Desktop.
JSON Stringify in Swift 4
This file contains hidden or 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
func jsonStringify(value: JSON) -> String { | |
let returnable = "" | |
if let data = try? JSONSerialization.data(withJSONObject: value, options: JSONSerialization.WritingOptions.sortedKeys) { | |
if let string = NSString(data: data, encoding: String.Encoding.utf8.rawValue) { | |
return string as String | |
} | |
} | |
return returnable | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment