Hello together,
I am developing some kind of "Product Overview"...
I receive this JSON from my API:
[
{
"id": 2,
"name": "Coca Cola",
"price": 2.2,
"ust": 19,
"options": [
"small",
"large"
]
}
]
Then I am decoding with this Codable:
struct Product: Identifiable, Codable {
var id: Int
var name: String
var price: Double
var ust: Int
var options: [String]?
}
And it throws an error when decoding:
AF.request("apiblablbablba").responseDecodable(of: [Product].self){response in
products = response.value ?? ([] as [Product])
if((response.error) != nil){
print(String(describing: response.error))
}
}
And ALL THESE PARTS result in this error:
Alamofire.AFError.responseSerializationFailed(reason: Alamofire.AFError.ResponseSerializationFailureReason.decodingFailed(error: Swift.DecodingError.typeMismatch(Swift.Array<Any>, Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 5", intValue: 5), CodingKeys(stringValue: "options", intValue: nil)], debugDescription: "Expected to decode Array<Any> but found a dictionary instead.", underlyingError: nil))))
I don't know why but CAN't find the problem! I already researched about the problem "Expected to decode Array but found a dictionary instead." - but they always said, the to the affected key corresponding value is a directory (so it is {bla}), but in my case it IS an array, isn't it?
I would be SO HAPPY if anybody could PLEASE help me with this!!!
Thanks and best greets,
Jannis