'Result<Any, AFError>' 类型的值没有成员 'value' JSON

Value of type 'Result<Any, AFError>' has no member 'value' JSON

有谁知道如何解决这个错误?对了,我是初学者,请客气!

AF.request(URL_LOGIN, method: .post, parameters: body, encoding: JSONEncoding.default, headers: header).responseJSON { (response) in
    
        if response.result.erro == nil {
            if let json = response.result.erro as? Dictionary<String, Any> {
                if let email = json["user"] as? String {
                    self.userEmail = email
                }
                if let token = json["token"] as? String {
                    self.authToken = token
                }
            }
            self.isLoggedIn = true
            completion(true)
        } else {
            completion(false)
            debugPrint(response.result.error as Any)

enter image description here

首先检查你的拼写,erro 毫无意义。

根据错误,result 的值是 Result<Any, AFError>Result 是一个具有关联类型的枚举和两种情况:successfailure

语法必须类似于

AF.request(URL_LOGIN, method: .post, parameters: body, encoding: JSONEncoding.default, headers: header).responseJSON { (response) in

    switch response.result {
      case .success(let result):
        if let json = result as? Dictionary<String, Any> {
            if let email = json["user"] as? String {
                self.userEmail = email
            }
            if let token = json["token"] as? String {
                self.authToken = token
            }
        }
        self.isLoggedIn = true
        completion(true)
      case .failure(let error):
        completion(false)
        debugPrint(error)
    }
}

逻辑不是很合逻辑。如果 emailtoken 无效,我确定 self.isLoggedIn 不应该是 true,并且在发生错误时应设置为 false