Skip to content

Instantly share code, notes, and snippets.

@kostapappas
Created September 3, 2019 10:15
Show Gist options
  • Save kostapappas/4544209462bc98c33727e0958f352dbb to your computer and use it in GitHub Desktop.
Save kostapappas/4544209462bc98c33727e0958f352dbb to your computer and use it in GitHub Desktop.
Json Data to String (for debug reasons)
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