-1

The number of posts is available in StackOverflow but i can't get the solution, I am using Alamofire Library and post my result to hit API but I'm not able to get the result please help me to fix it.

{   
           "People":{ "Prefix": "Mr.",
            "FirstName": "Eric",
            "MiddleName": null,
            "LastName": "John",
            "FullName": "Smith GOldi6",
            "Email1": "abc123@example.com",
            "Email2": null,
            "PhoneNumber1": "0000",
            "PhoneNumber2": null,
            "DateOfBirth": "1975-01-01T00:00:00",
            "Status": 3,
            "DeleteFlag": true,
            "Comments": null,
            "Description": null,
            "UserName": "abc123"
           },
            "Password": "password1"
}

this is the result which I create in parameters to post.

Alamofire.request(signup_api, method: .post, parameters: parameters, encoding: URLEncoding.httpBody).responseJSON { (response) in

                switch response.result {
                case .success(let data) :
                    let json = JSON(data)

                    print("response.result = \(response.result)")
                    print("response = \(response)")
                    let resJson = JSON(response.result.value!)


                    print("success = \(resJson)")

                    if (resJson.count == 0) {
                        if (resJson.null == nil) {
    //                        self.DimBackground.isHidden = true
    //                        self.activator.stopAnimating()
                        }
                        return
                    }

                    if let err = response.error{
                        print("err === \(err)")
                        return
                    }

                    return

                case .failure(let _error):
                    print("_error = \(_error)")
                    print("false")
                    print("response.result = \(response.result)")
                    print("response = \(response)")
                    print("Network Problem: There might be an issue with your internet connection, or server not responding. Please try again.")
                    return
                }

            }

This shows this error:

_error = responseSerializationFailed(reason: Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(error: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.})) false response.result = FAILURE response = FAILURE: responseSerializationFailed(reason: Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(error: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))

Magnas
  • 3,832
  • 5
  • 33
  • 48

1 Answers1

-1

if you are getting proper JSON response than there should be issue in your condition

if (resJson.count == 0) 

Actually there should be status (true/false) in your response so you get idea which action you need to take if status is true than you have to get proper data from response and processed for further. else you have to show error message and stop for processed further.

Shreyank
  • 1,549
  • 13
  • 24