后台返回时的处理方法

当后台返回时,需要先转化成AnyObject,然后判断通过isEqual是否为NSNull()

static func getRequest(url : String, params : [String : Any]? = nil, finshCallBack : @escaping (T) -> ()){
        let requestUrl : String = Server_URL + url
        HUD.show(.labeledProgress(title: "请求中...", subtitle: ""))
        
        NetworkSessionManager.sharedSessionManager.request(requestUrl, method: HTTPMethod.get, parameters: params, encoding: URLEncoding.default, headers: UserDefaults.getRequestHeaders())
            .validate({ (request, respnse, data) -> Request.ValidationResult in
                return .success
            })
            .responseJSON { (response) in
                HUD.hide()
                switch response.result {
                case .success(let data): do {
                    switch response.response?.statusCode {
                    case 200: do {
                        if ((data as! [String : Any])["data"] as AnyObject).isEqual(NSNull()) {
                            return
                        }
                        let model = Mapper().map(JSON: (data as! [String : Any])["data"] as! [String : Any])!
                        finshCallBack(model)
                        }
                    default: do{
                        let messageM = Mapper().map(JSON: data as! [String : Any])
                        HUD.flash(.label(messageM?.message), delay: 0.5)
                        }
                    }
                    }
                case .failure(let error): do{
                    switch response.response?.statusCode {
                    case 403: do {
                        HUD.flash(.label("请不要点击太快"), delay: 0.5)
                        }
                    default: do{
                        print("=== \(error)")
                        //                    HUD.flash(.label(error.localizedDescription), delay: 0.5)
                        }
                    }
                    }
                }
        }

你可能感兴趣的:(后台返回时的处理方法)