Convert the Dictionary to JSON iOS swift
Solution:
The below function was used to convert the dictionary to jsonobject.
You can call the function like below.
Code:
The below function was used to convert the dictionary to jsonobject.
You can call the function like below.
convertToJSON(dict: dictionary)
func convertToJSON(dict: NSDictionary) -> String{
if let theJSONData = try? JSONSerialization.data(
withJSONObject: dict,
options: []) {
let theJSONText = String(data: theJSONData,
encoding: .ascii)
print("JSON string = \(theJSONText!)")
return theJSONText!
}
return ""
}
Comments
Post a Comment