【发布时间】:2019-05-29 06:24:11
【问题描述】:
我收到此行的错误:
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")
}
我该如何解决?我已经尝试了太多东西,但我还是坚持了下来。
【问题讨论】:
-
这是什么魔法:
responseValue.utf8 as! Decoder?如果你只使用responseValue会有什么结果? -
什么是
responseValue? -
@JoakimDanielson 从 API 获取响应
-
@Lu_ 我没有得到任何响应,因为我附上了屏幕截图,因为错误没有编译。请检查
-
我的意思是,它是什么类型的?如果它已经是数据,那么我假设你不需要对它做任何事情。