How i can convert diction list to json ?
struct User: Codable {
var id = ""
var deviceName = ""
}
var userList:[Any] = []
for user in users {
var b : [String: Any] = [:]
b["name"] = user.deviceName
b["id"] = user.id
// b["uuid"] = user.uuid.uuidString
userList.append(b)
}
print(JSONSerialization.isValidJSONObject(userList))
do {
let jsonData = try JSONSerialization.data(withJSONObject: userList, options: .prettyPrinted)
return .ok(.json(jsonData))
} catch {
return .ok(.htmlBody("Error"))
}
terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__NSConcreteUUID)' terminating with uncaught exception of type NSException