切勿
error.localizedDescription在解码
catch块中打印。这将返回一个毫无意义的通用错误消息。始终打印
error实例。然后,您会得到所需的信息。
let deprer = JSonDeprer() if let data = data { do { // process data } catch {print(error) }或针对 全部 错误使用
let deprer = JSonDeprer()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) }


