I have a struct which has "fill" value. And that value contains Int, but in one case it has String value and I don’t know how to pair that.
Here’s the decodable JSON, I’m just showing this part, because as I think that’s where the problem is. It works fine, only that fontSize gives me headache. I don’t know how to pair it.
struct Element: Codable, Identifiable{
var text: String?
var textArray: [String]?
var id: String?
var image_url: String?
var type : String
var zIndex : Int
var x: Double
var y: Double
var width: Double?
var height: Double?
var fill: String?
var fontSize: Int? <-- ISSUE
}
And here I want to show json
This is Int:
"fontSize": 20,
This is String:
"fontSize": "1",
Both of those values in one json!
I’ve tried to use struct it doesn’t help me. Or I’m doing smt wrong. Also I’ve tried enum and still no result. Can you please tell me where my problem is.
2
Answers
You need to decode
fontSize
manually, something like:Try to mock up with some sample JSON
You can use as
Any
for such to avoid crashing…Output