json - Alamofire 5 headers GET 方法在 Swift 5 中返回无效的 json

标签 json swift alamofire

我正在使用 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/

相关文章:

ios - AlamofireObjectMapper 无法推断通用参数 'T'

java - 我正在尝试在 java 中合并两个 JsonObjects

ios - ObjectiveDDP 和 meteor 更新/插入集合

javascript - 如何使用 Windows 8 JSON.parse 将 JSON 文本反序列化为日期类型?

asp.net - 如何在 Asp.net mvc 3 Controller 中创建 Json 对象?

ios - 无法从 Assets 中选择文件夹

ios - Swift UITextFields 跳回到位置

ios - 设置 UIPageViewController.dataSource 时发送到实例的无法识别的选择器?

swift - 不使用 Alamofire 应用 HTTP POST header 数据

ios - 使用 Alamofire 调用服务器时未调用 UICollectionView cellForItemAtIndexPath