这是我的 api 请求
这是我的请求参数和 API 调用
var param = [String:Any]()
param["TokenID"] = tokenId
param["RID"] = Rid
param["FromDate"] = DateUtilities.convertStringfromDate(date: DateUtilities.getDateofMonthStartOfLast2Month())
param["ToDate"] = DateUtilities.convertStringfromDate(date: Date())
print(param)
// Network request
Alamofire.request(finalURL, method: .post, parameters: param, encoding: URLEncoding.queryString, headers: headers).responseJSON { (response: DataResponse<Any>) in
// check result is success
guard response.result.isSuccess else {
failure((response.result.error?.localizedDescription)!,"100")
return
}
if let arrResponse = response.result.value as? [[String: Any]]{
// get status code
if arrResponse[0]["Status"] as? String ?? "" == "Error"{
let statusCode = arrResponse[0][Constants.ResponseKey.code] as? String ?? "0"
if statusCode == "8"{
//Call logout api
ApplicationData.sharedInstance.logoutUser()
return
}
// get status message
let message = arrResponse[0][Constants.ResponseKey.message] as? String ?? ""
failure(message,statusCode)
return
}
success(arrResponse, "")
return
}
}
但是由于序列不匹配,我没有得到所需的响应,我在 api 响应中收到错误。这里我认为这是 alamofire 的问题,它将参数排序到查询字符串中。如何避免在请求中排序?
请帮我解决。
最佳答案
显然,这是 Alamofire 上的一个已解决问题,请关注此 link 。
Unfortunately Swift's dictionaries aren't order preserving, so there's no way to currently accomplish this.
Alamofire currently encodes URL parameters in alphabetical order, but there's no way to preserve an arbitrary ordering in the dictionary. So unless the order is want is a sort of some kind, or the arbitrary ordering of the dictionary.
关于ios - 不想按排序顺序对参数进行排序 alamofire,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52990765/