我收到此行的错误:
Data(from: responseValue.utf8 as! Decoder)
Cannot convert value of type 'Data' to expected argument type 'Data'
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")
}
我该如何解决?我已经尝试了太多东西,但我坚持不懈。
最佳答案
根据报错信息,很简单
let responseData = try JSONDecoder().decode(forget_Base.self, from: Data(responseValue.utf8))
转换为 Decoder
的类型无论如何都是毫无意义的。
并且请遵守命名约定,forget_Base
太可怕了,将其命名为ForgetBase
关于ios - 以 UTF-8 格式转换响应时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56354286/