StackOverflow中提供了帖子数量,但我无法获得解决方案,我正在使用Alamofire库并将结果发布到API中,但无法获取结果,请帮助我修复它。< / p>
{
"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"
}
这是我在要发布的参数中创建的结果。
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
}
}
这显示此错误:
_error = responseSerializationFailed(原因:Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(错误: 错误域= NSCocoaErrorDomain代码= 3840“周围的无效值 字符0。“ UserInfo = {NSDebugDescription =无效值 字符0。}))false response.result = FAILURE response = FAILURE: responseSerializationFailed(原因: Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(错误: 错误域= NSCocoaErrorDomain代码= 3840“周围的无效值 字符0。“ UserInfo = {NSDebugDescription =无效值 字符0。}))
答案 0 :(得分:-1)
如果您获得正确的JSON响应,则说明您的情况应该存在问题
if (resJson.count == 0)
实际上,您的响应中应该有状态(是/否),因此您可以了解状态为真时需要采取的措施,而不是从响应中获取适当的数据并进行进一步处理。否则,您必须显示错误消息并停止进一步处理。