Я пытаюсь понять, что не так в моем декодировании JSON. Я всегда получаю одну и ту же ошибку: ожидается декодирование Dictionary‹String, Any›, но вместо этого найден массив. Пытаясь помочь себе, я сделал игровую площадку из простого случая, чтобы попытаться изолировать проблему:
import Foundation
let json = """
[{
"meta": {
"id": "above:1",
"uuid": "f9ccfcaa-836c-4402-b2e8-5ef6e0f13eac",
"src": "int_dict",
"section": "alpha",
"stems": ["above"],
"offensive": false
}
}
]
"""
struct Word: Decodable {
let meta: [String]
let id: String
let uuid: String
let src: String
let section: String
let stems: [String]
let offensive: Bool
}
let jsonData = json.data(using: .utf8)!
let decoder = JSONDecoder()
let word = try decoder.decode(Word.self, from: jsonData)
print (word)
Я получаю ту же ошибку:
Playground execution terminated: An error was thrown and was not caught:
▿ DecodingError
▿ typeMismatch : 2 elements
- .0 : Swift.Dictionary<Swift.String, Any>
▿ .1 : Context
- codingPath : 0 elements
- debugDescription : "Expected to decode Dictionary<String, Any> but found an array instead."
- underlyingError : nil
В чем ошибка?
Спасибо
Эли