I have an error: Expected to decode Array but found a dictionary instead.", underlyingError: nil)
I use Moya and have JSON:
"buttons" : [
{
"name" : "chat",
"title" : "Сообщения",
"active" : true
},
{
"title" : "Управление заявкой",
"active" : true,
"name" : "posterRecordActions",
"actions" : {
"name" : "cancelPosterRecord",
"title" : "Отменить заявку",
"active" : true
}
}
]
My Struct:
struct Record: Codable {
let id: Int
let title: String
@FailableURL var image: URL?
let statusTitle: String
let statusColorName: String
let price: Int
let startTime: Int
let description: String?
let placeTitle: String
let members: [Members]
let rules: String?
let recordForm: [String]
let buttons: [API.Posters.RequestButtons]
struct RequestButtons: Codable {
let name: RequestButtonName
let title: String
let active: Bool?
let actions: [RequestButtons]?
let paymentLink: String?
let paymentContext: String?
let value: String?
let badge: Int?
}
I think, they problems with actions inside buttons, but I can't resolve this(
Actionsin your JSON is NOT array, it's a dictionary.Change your struct like below code:
Additionally, I suggest to read swift API design for your naming convention; API Design Guidelines
For example
RequestButtonshave to beRequestButtonoractionsin your case have to beaction, because they're not plural