0

this is error happed when making api request .

Alamofire.AFError.ResponseSerializationFailureReason.decodingFailed(error: Swift.DecodingError.dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))))))

this is response from API

{
    "IsSuccess": true,
    "Message": "تم التسجيل بنجاح",
    "Status": 200,
    "token": "8Bmz8iORolTfkkQ5kKrpv5AAucVwmHSmCAqrPg-AGy5K0AF0YTOPV-2nTOMjtiqKuu17eIGE0eJaAVI2lYAAnnw5b6KAPCB92VPXTh5SfHG2EkHUZFQYeaO6dUyoiiWBU8qh4cCp6BFxFVEl24Q0Isk53ZeDIuXb6RJO4Ygrm52MC_asVRv14aDFRZ2iuuccCgG2cBJgoRUCQO8TF-lmEFeFRnRYaKZLVKWDrsMLKkNfu0s-aJgS5mW-k9Fw1QKB6zicUA7dh6G_Z1kts8a6z7ye5JFdX1q2_SSsnz0DtbpbhUCutaQfvFpvnjybKw76JE1Ed2He61PGIGZvtzeWqI_Kay67mJ5U6z46KFPCsoKwy3-wSzHH-oa_fpyJAP2TX2fSzT5FT05LtjcjoZi5y_MZzSqoRHD0C6h_CG4CAkgxnlXTgflUODcebk6bVscazLtJZPU7pU-YORZlljPa_ZxMRAATKYwVo3R0bvsQNalFJUVZyUWZkjv4AwcgDLJ9S6FtNXDOQFA1HCDFO-RsOw",
    "tokenType": "Bearer"
}

// this my Model

import Foundation
struct UserModelResponse :Codable {
    let isSuccess: Bool?
    let message: String?
    let status: Int?
    let token, tokenType: String?

enum CodingKeys: String, CodingKey {
    case isSuccess = "IsSuccess"
    case message = "Message"
    case status = "Status"
    case token, tokenType
}

}

  • 1
    "this is response from API" How did you get that? Could you print if not done from the closure of Alamofire where you get the error? If that's already from that, maybe the raw data to hex string (see https://stackoverflow.com/questions/39075043/how-to-convert-data-to-hex-string-in-swift) – Larme Aug 20 '21 at 09:45
  • *This is **not** response from API*. The error describes likely a server communication error. The received data represents HTML You should handle the response error. – vadian Aug 20 '21 at 09:46
  • @vadian can you show me how can handle this error ? – Mohamed Elkilany Aug 20 '21 at 12:43
  • Make a string from the received data and `print` it to figure out what it is. – vadian Aug 20 '21 at 12:44
  • Show the code where your printed the error. Find how to print the received data into a String (with utf8 encoding), if not working, print the hex data. – Larme Aug 20 '21 at 12:57

0 Answers0