(Cocoa error 3840.)" (Invalid value around character 0.) AFNetworking (Cocoa error 3840.)" (Invalid value around character 0.) AFNetworking ios ios

(Cocoa error 3840.)" (Invalid value around character 0.) AFNetworking


Judging by the discussion in the comments it appears that your GET request is successful (response code 200), but the response body is not valid JSON (nor a JSON fragment) as you have requested by your use of AFJSONResponseSerializer. A basic AFHTTPResponseSerializer can be used for responses that are not JSON.


I am pretty sure that you have a valid response from server but your response is not a valid format in JSON, probably because you have carachters in front of first { .Please try this: Put the same URL address manually in your browser and you will see the culprit in the response. Hope it helped.


Hey guys this is what I found to be my issue: I was calling Alamofire via a function to Authenticate Users: I used the function "Login User" With the parameters that would be called from the "body"(email: String, password: String) That would be passed

my errr was exactly:

optional(alamofire.aferror.responseserializationfailed(alamofire.aferror.responseserializationfailurereason.jsonserializationfailed(error domain=nscocoaerrordomain code=3840 "invalid value around character 0." userinfo={nsdebugdescription=invalid value around character 0

character 0 is the key here: meaning the the call for the "email" was not matching the parameters: See the code below

func loginUser(email: String, password: String, completed: @escaping downloadComplete) { let lowerCasedEmail = email.lowercased()

    let header = [        "Content-Type" : "application/json; charset=utf-8"    ]    let body: [String: Any] = [        "email": lowerCasedEmail,        "password": password    ]    Alamofire.request(LOGIN_USER, method: .post, parameters: body, encoding: JSONEncoding.default, headers: header).responseJSON { (response) in        if response.result.error == nil {            if let data = response.result.value as? Dictionary<String, AnyObject> {                if let email = data["user"] as? String {                    self.userEmail = email                    print(self.userEmail)                }                if let token = data["token"] as? String {                    self.token_Key = token                    print(self.token_Key)                }

"email" in function parameters must match the let "email" when parsing then it will work..I no longer got the error...And character 0 was the "email" in the "body" parameter for the Alamofire request:

Hope this helps


matomo