此行出现错误:
Data(from: responseValue.utf8 as! Decoder)
无法将“数据”类型的值转换为预期的参数类型“数据”
do{
let responseData = try JSONDecoder().decode(forget_Base.self, from: Data(from: responseValue.utf8 as! Decoder))
if responseData.code == 200
{
let message = isNilValue(assignValue: responseData.message)
let alert = UIAlertController(title: "", message: message, preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: {(_action) -> Void in
let next = self.storyboard?.instantiateViewController(withIdentifier: "SetPasswordVCSID")
self.navigationController?.pushViewController(next!, animated: true)
})
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
}
else
{
}
}
catch
{
print("error")
}
我该如何解决?我已经尝试了太多东西,但仍然坚持下去。
答案 0 :(得分:1)
根据错误消息,很简单
let responseData = try JSONDecoder().decode(forget_Base.self, from: Data(responseValue.utf8))
强制转换为Decoder
的类型毫无意义。
请遵守命名约定,forget_Base
很可怕,将其命名为ForgetBase
答案 1 :(得分:0)
照原样使用responseValue。 这是代码: 更改以下内容
let responseData = try JSONDecoder().decode(forget_Base.self, from: Data(from: responseValue.utf8 as! Decoder))
到
let responseData = try JSONDecoder().decode(forget_Base.self, from:responseValue)