我發現一些線程相同的問題,但他們的答案不適合我。Swift - Alamofire「字符0周圍的值無效」
我有一個post
請求檢查用戶登錄。
URL格式:
「http://support.xxx.xx:8031/serpapi/login/checkLogin」
參數:
["contextInfo" :
["clientId": "1000000", "orgId": "1000001",
"warehouseId": "1000002", "roleId": "0"],
"userName": "hanoiaUser", "password": "hanoiaUser"]
請求:
Alamofire.request(url!, method: .post, parameters: params).responseJSON { (response) in
print(response)
}
錯誤響應:
FAILURE: responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))
爲什麼會出現這個錯誤?以及如何解決它?
編輯:我試圖與郵遞員,它返回的響應:
內容類型:應用程序/ JSON
身體:原料 - JSON
{
"contextInfo" : {
"clientId":1000000,
"orgId": 1000001,
"warehouseId": 1000002,
"roleId": 0
},
"userName": "hanoiaUser",
"password": "hanoiaUser"
}
RESPONSE:
{
"success": true,
"data": [
{
"userId": 1000003,
"userName": "hanoiaUser",
"token": "b7e804d25065e5c3ac97d765180b7986"
}
],
"error": null
}
它與你的服務器有問題可能 – Siyavash
顯然,反應不JSON有效。你可以使用'responseString'來代替並顯示那個字符串嗎? – Larme
我已經嘗試過了,但它返回了另一個錯誤:「錯誤415不支持的媒體類型」 –