我正在使用 Alamofire 5。我有带有 header 参数的 GET 请求。但是当我在 postman 中被调用时,它返回正确的 json。在 Alamofire 中,它返回错误的 json,如下所示:
success({
"country_id" = 3;
"customer_id" = 1;
"language_id" = 1;
profile = {
address1 = "";
address2 = "";
}
})
这是我的 postman json
{ "type_id": 1,
"country_id": 3,
"language_id": 1,
"customer_id": 1,
"parent_user_id": null,
"profile": {
"image": "xiOHhaFfBXaMHewCwznPjejMPWrle48KEiDh75eh.png",
"mob2": "",
}
}
这是我用于获取数据的代码:
func getProfileInfo() {
let headers: HTTPHeaders = [
"Content-Type": "application/json",
"YumaSession": "424142411"
]
AF.request(url, headers: headers).validate().responseJSON { response in
print(response)
switch response.result {
case .success(let responseData):
case .failure(let error):
Custom_Progress_Bar.hide_progress_dialog()
print("error--->",error)
}
}
}
请帮我看看我的代码有什么问题。
最佳答案
您打印的不是 JSON,而是 Result
的打印描述,它看起来不像 JSON。打印 response.debugDescription
或使用 debugPrint(response)
查看您的 body 数据的实际情况。此外,如果您使用不同的 YumaSession
值,我希望得到不同的配置文件响应。
关于json - Alamofire 5 headers GET 方法在 Swift 5 中返回无效的 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59052514/