Никогда печать error.localizedDescription
в блоке декодирования catch
.Это возвращает совершенно бессмысленное общее сообщение об ошибке.Печатайте всегда экземпляр error
.Тогда вы получите желаемую информацию.
let decoder = JSONDecoder()
if let data = data {
do {
// process data
} catch {
print(error)
}
Или для набора full используйте
let decoder = JSONDecoder()
if let data = data {
do {
// process data
} catch let DecodingError.dataCorrupted(context) {
print(context)
} catch let DecodingError.keyNotFound(key, context) {
print("Key '\(key)' not found:", context.debugDescription)
print("codingPath:", context.codingPath)
} catch let DecodingError.valueNotFound(value, context) {
print("Value '\(value)' not found:", context.debugDescription)
print("codingPath:", context.codingPath)
} catch let DecodingError.typeMismatch(type, context) {
print("Type '\(type)' mismatch:", context.debugDescription)
print("codingPath:", context.codingPath)
} catch {
print("error: ", error)
}