I'm connecting to my server on localhost to fetch some data. The data returned to this request is a JSON, on Postman the JSON is correctly shown, but when I'm playing with iOS, Alamofire returns me an error:
responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Garbage at end." UserInfo={NSDebugDescription=Garbage at end.}))
The JSON in question is:
{ "name": "TestName", "surname": "TestSurname" } The thing that I do not understand is that if I force my server to return the json in form of a string so something like
"{"name": "TestName after update","surname": "TestSurname"}" Alamofire does not complain and parses it correctly. How is that? I thought that specifying the parameter responseJSON it would have worked the other way around.
Alamofire.request("http://192.168.1.4:8080/user/abcdf").validate().responseJSON { response in switch response.result { case .success: // DO stuff case .failure(let error): print(error) } } 