Get json string from array iOS swift
Solution:
func jsonStringFromArray(array:NSArray) -> String {
var str = ""
do {
//Convert to Data
let jsonData = try JSONSerialization.data(withJSONObject: array, options: JSONSerialization.WritingOptions.prettyPrinted)
if let JSONString = String(data: jsonData, encoding: String.Encoding.utf8) {
str = JSONString
}
var json = try JSONSerialization.jsonObject(with: jsonData, options: JSONSerialization.ReadingOptions.mutableContainers) as? [String: Any]
} catch {
print(error)
}
return str
}
Comments
Post a Comment