不想在排序顺序alamofire中对参数进行排序

问题描述 投票:0回答:1

这是我对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

这是我的请求param和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的问题,它将参数排序为查询字符串。如何避免在请求中排序?

请帮帮我。

ios swift sorting request alamofire
1个回答
0
投票

显然这是关于Alamofire的封闭问题已经关注这个link

不幸的是,Swift的字典不是保留订单的,因此目前无法实现这一目标。

Alamofire目前按字母顺序对URL参数进行编码,但是没有办法在字典中保留任意排序。因此,除非订单需要某种类型,或字典的任意排序。

© www.soinside.com 2019 - 2024. All rights reserved.