Looking for help to decode irregular (for a lack of a better word) json. As an example:
[
{
"texts":
[
{
"value": "value 1"
}
],
"commentType": "someComment"
},
{
"texts":
[
{
"value": "value 2"
}
],
"commentType": "someComment2"
},
{
"texts":
[
{
"evidences":
[
{
"evidenceCode": "code 1",
},
{
"evidenceCode": "code 2",
},
{
"evidenceCode": "code 3",
},
{
"evidenceCode": "code 4",
}
],
"value": "value 3"
}
],
"commentType": "someComment3"
}
]
I can decode comment and the first two "texts":
enum CodingKeys: String, CodingKey {
case texts
case commentType
}
do {
let container = try decoder.container(keyedBy: CodingKeys.self)
let name = try container.decode(String.self, forKey: .commentType)
if let texts = try container.decodeIfPresent([[String: String]].self, forKey: .texts) {
for text in texts {
if let value = text["value"] {
// add to model object
}
}
}
} catch {
print(error)
}
But I get an error for the third "texts" block:
"Expected to decode String but found an array instead."
Which I understand, since now instead of an array of [String:String], it is a mixed array of [String:[String:String] and [String:String].
How do I decode value3 from that third block?