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

前端 未结 3 1453
名媛妹妹
名媛妹妹 2020-12-03 17:42

Been working on this for a bit with no success. I have a function that goes to a UIButton solely to perform alamofire calls to my rails api which uses all JSON.

相关标签:
3条回答
  • 2020-12-03 17:50

    You need to check the mimeType it will be "text/plain" instead of "application/json". That's why JSONSerialization class not able to parse the data.

    0 讨论(0)
  • 2020-12-03 17:59

    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")
        }
    
    })
    
    0 讨论(0)
  • 2020-12-03 18:03

    The response returned by the server is not in the JSON format. You can use the tool to test the request first.

    Print out of the error code is not a HTTP error code, because of the failure to resolve JSON

    0 讨论(0)
提交回复
热议问题