alamofire.error Code=-6006 “JSON could not be serialized

This is not Alamofire or swift error, The response returned by the server is not in the JSON format. you can print out response data and check what is wrong in this.

try this code to print out our server data to easily identifying to error and resolve this.

Alamofire.request("Your url").responseJSON(completionHandler: { (response) in
    switch response.result {
    case .success(let value):
        break

    case .failure(let error):
        print("\n\n===========Error===========")
        print("Error Code: \(error._code)")
        print("Error Messsage: \(error.localizedDescription)")
        if let data = response.data, let str = String(data: data, encoding: String.Encoding.utf8){
            print("Server Error: " + str)
        }
        debugPrint(error as Any)
        print("===========================\n\n")
    }

})

Leave a Comment