Get the string from NSMutableDictionary iOS swift
Problem:
I had nsdictionary format of my object.I want to send the dictionary as string to server.How to convert entire dictionary into string format with accessible.
Solution:
extension NSMutableDictionary {
func getString() -> String {
do {
let jsonData = try JSONSerialization.data(withJSONObject: self)
if let json = String(data: jsonData, encoding: .utf8) {
return json
}
} catch {
print("something went wrong with parsing json")
}
return ""
}
}
You can use the above extension to convert the dictionary to string.
Call the above function as like below
yourdic.getString()
Comments
Post a Comment