【发布时间】:2020-07-09 05:06:57
【问题描述】:
我正在使用 JSONDecoder 将 JSON 转换为对象。
这里是代码。它通常工作正常。
do{
print("Hi")
if Data != nil{
let model = try JSONDecoder().decode(Base.self, from: Data!)
}
}
catch{
print("Error:\(error)")
}
但我正在低于错误
错误:类型不匹配(Swift.Double, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: “棒”,intValue:无),编码键(stringValue:“点头”,intValue:无), _JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "meta", intValue: nil), CodingKeys(stringValue: "label", intValue: nil)], debugDescription: "预期解码 Double 但发现 字符串/数据。”,基础错误:无))
它曾经工作得很好。任何解决此问题的帮助将不胜感激
【问题讨论】:
-
请仔细阅读错误信息。这很清楚。字典
rod中数组nod的第一项中的字典meta中键label的值是String,而不是预期的Double。
标签: ios json swift jsondecoder