gpt4 book ai didi

ios - 不想按排序顺序对参数进行排序 alamofire

转载 作者:行者123 更新时间:2023-11-30 11:03:39 24 4
gpt4 key购买 nike

这是我的 api 请求

http://xxxxxxxxxxxxxx/Service/GetEntry.aspx?FromDate=01/08/2018&RID=1&ToDate=25/10/2018&TokenID=1e731b96-4261-453b-848c-5b1a0d44f808

但我原来的要求是这样的 http://xxxxxxxxxxxxx/Service1/GetEntry.aspx?TokenID=5edc678f-82ee-4cf8-956e-5f1d3798dfec&RID=1&FromDate=01%2F08%2F2018&ToDate=25%2F10%2F2018

这是我的请求参数和 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com