Last active
January 30, 2017 10:13
-
-
Save ramakser/4a7ca57996df06ef39ba08cbb5b9823e to your computer and use it in GitHub Desktop.
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
func JSONStringify(value: [String: AnyHashable],prettyPrinted:Bool = false) -> String{ | |
let options = prettyPrinted ? JSONSerialization.WritingOptions.prettyPrinted : JSONSerialization.WritingOptions(rawValue: 0) | |
if JSONSerialization.isValidJSONObject(value) { | |
do { | |
let data = try JSONSerialization.data(withJSONObject: value, options: options) | |
if let string = NSString(data: data, encoding: String.Encoding.utf8.rawValue) { | |
return string as String | |
} | |
} catch { | |
print("error") | |
} | |
} | |
return "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment