I have to encode a [String:Any] object to a JSON like this:
{
"timestamp": "2021-06-17T09:18:30.212Z",
"readings": [
{
"uuid": "string",
"major": 0,
"minor": 0,
"macAddress": "string",
"rssi": 0
}
]
}
I have a Codable class to handle "readings":
class BeaconData: Codable {
var uuid: String
var major: Int
var minor: Int
var rssi: Double
init(uuid: String, major: Int, minor: Int, rssi: Double) {
self.uuid = uuid
self.major = major
self.minor = minor
self.rssi = rssi
}
}
While timestamp is a String. I created a [String:Any] object to contain those data:
let parameters = ["timestamp": myTimestampString, "readings": myArrayOfBeaconData]
...but if I try to encode it with JSONEncoder
let data = JSONEncoder().encode(parameters)
...it returns that:
Protocol 'Any' as a type cannot conform to 'Encodable'
Any suggestions on how to organize those data to encode them without creating a new Root struct?