ios - 以 UTF-8 格式转换响应时出现问题

标签 ios swift encoding decode

我收到此行的错误:

Data(from: responseValue.utf8 as! Decoder)

enter image description here )

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/

相关文章:

video - bsf过滤器有什么区别? (ffmpeg)

python - Google 翻译在 Python 3 中输出 HTML 实体

uilabel - 如何使用 swift 更改标签中的文本?

ios - 读取用户可访问的文件时遇到问题

android - AppStore 中有新版本时如何更新基于 Cordova 的应用程序?

ios - 在水平 UIStackView 的每一端布局两个 UILabels

ios - UICollectionViewCell 与异步图像重用加载错误图像

arrays - 如何通过 Swift 中的 for 循环将数组的所有元素附加到标签

sql - 使用 dplyr 和 SQLite 进行 UTF-8 编码

ios - 我的 iOS 应用程序需要很长时间才能回到前面