I have an Object of type [Dictionary<String: Any>]
[{
"addCity" : "Xyz",
"addLandmark" : "Shopper",
"addCountry" : "Abc",
"addPincode" : "122001",
"isPrimary" : "false",
"addAddress" : "S44",
"addState" : "abc",
"addAddress2" : "Grand Road",
"addContact" : "11111111",
"addName" : "John"
}]
and want to convert this into this:
"{\"addAddress\":\"S44\",\"addAddress2\":\"Grand Road\",\"addCity\":\"Xyz\",\"addContact\":\"11111111\",\"addCountry\":\"abc\",\"addLandmark\":\"Shopper\",\"addName\":\" John\",\"addPincode\":\"122002\",\"addState\":\"abc\",\"isPrimary\":true}"
means I have to stringify the above values and tried various methods but not reached to any solution.
I have tried this
do {
let arrJson = try JSONSerialization.data(withJSONObject: dataAddress, options: JSONSerialization.WritingOptions.prettyPrinted)
let string = String(data: arrJson, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
let tempJson = string! as String
print("%%%%%%",tempJson)
} catch let error as NSError {
print(error.description)
}
but it just returned the same in JSON form.
Please can anyone help me.