I receive server response which contains geojson I need to have the geojson as string and don’t want to decode it, but this code throws type mismatch exception.
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id_s = try container.decode(String.self, forKey: .id_s)
name = try container.decode(String.self, forKey: .name)
description = try container.decode(String.self, forKey: .description)
area_type = try container.decode(String.self, forKey: .area_type)
active = String(try container.decode(Bool.self, forKey: .active))
danger = String(try container.decode(Bool.self, forKey: .danger))
scheduled_from = try container.decodeIfPresent(String.self, forKey: .scheduled_from)
scheduled_to = try container.decodeIfPresent(String.self, forKey: .scheduled_to)
let geojsonString = try container.decode(String.self, forKey: .geojson)
// I need the raw geojson string, not a decoded dictionary
// I get "Expected to decode String but found a dictionary instead"
}
I tried let geojson = try container.decode(String.self, forKey: .geojson)
and et geojson = try container.decode([String, Any].self, forKey: .geojson)
New contributor
Zahid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.