![](/img/trans.png)
[英]Could not cast value of type '__NSDictionaryI' to 'NSMutableDictionary'
[英]Could not cast value of type '__NSDictionaryI' to 'NSData'
我正在嘗試解碼以下數據:
AF.upload(postData!, to: loginUrlString, headers: postmanManager.headers).responseJSON { response in
switch response.result {
case .success(let value):
print(value)
do {
let results = try JSONDecoder().decode(User.self, from: value as! Data)
DispatchQueue.main.async {
let id = results.Usuario[0].Id
let name = results.Usuario[0].Name
let userInfo = UserModel(Id: id, firstName: name)
print(userInfo)
}
} catch {
print(error)
}
case .failure(let error):
print(error)
}
}
'User' object 屬於以下結構:
struct User: Codable {
let Usuario: [UserData]
}
struct UserData: Codable {
let Id: Int
let Name: String
}
我嘗試查找答案,根據我的理解,我嘗試將value as! Data
value as! Data
value as: [String: Any]
,但我得到另一個錯誤:
Cannot convert value of type '[String: Any]' to expected argument type 'Data'
我還能嘗試改變什么? 謝謝您的幫助!
您使用了錯誤的響應類型。
代替
.responseJSON
和
.responseData
並且請以小寫字母開頭命名函數和變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.