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

标签 ios swift sorting request alamofire

这是我的 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/

相关文章:

java - 在具有空值的情况下按列对二维 Java 字符串数组进行排序

ios - 如何将 UITextView 添加到 UITableView 详细信息

ios - NSImage 和 UIImage 给出了不同的 NSData 表示

ios - AF 网络 2.0 : Passing header information

objective-c - Core Data无法批量处理很多记录?

ios - 调度定时器源中的数据争用

c++ - STL排序算法

ios - 解读iOS崩溃日志与-[UIApplication _cachedSystemAnimationFenceCreatingIfNecessary :]

ios - 如何在 Swift 中使用 UIWebView 管理 cookie

algorithm - 按相对位置对数组排序