Created
September 3, 2019 10:15
-
-
Save kostapappas/4544209462bc98c33727e0958f352dbb to your computer and use it in GitHub Desktop.
Json Data to String (for debug reasons)
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
private func stringify(jsonData: Data) -> String { | |
do { | |
let array = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any] | |
let jsonData2 = try JSONSerialization.data(withJSONObject: array, | |
options: .prettyPrinted) | |
// here "jsonData" is the dictionary encoded in JSON data | |
let jsonString = String(data: jsonData2, encoding: .utf8) ?? "" | |
let result = String(jsonString.filter { !" \n\t\r".contains($0) }) | |
return result | |
} catch { | |
} | |
return "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment