如何快速将请求发送到alamofire之前如何安排数组

问题描述 投票:1回答:1
let request = NSMutableDictionary()
request.setDictionary([ "merchant_reference":getRandomMerchant, "merchant_identifier":"e54638eb", "access_code":"hRRVGXrIpHSYoH19Ebwt", "signature": base64Str, "service_command":"OTP_GENERATE", "language":"en", "payment_option":"VALU", "phone_number":"01008606003", "merchant_order_id":getRandomMerchant, "amount":getTotal, "currency":"EGP", "products":[ [ "product_name": getName, "product_price": getTotal, "product_category":getProductType ] ] ])

Alamofire.request(URLAPi.URL_Payment_Api ,
                  method : .post ,
                  parameters : (request as! Parameters) ,
                  encoding: JSONEncoding.default
).responseJSON { (response) in
    debugPrint(response)
    if response.result.isSuccess {
        let jsonpayfortrequest : JSON = JSON(response.result.value!)
        var resultsArray = jsonpayfortrequest.arrayValue
        var sortedResults = resultsArray.sorted { $0.stringValue > $1.stringValue }
        print(jsonpayfortrequest)
        print(resultsArray)
        print(sortedResults)
        print(jsonpayfortrequest.sorted(by: {$0 > $1}))
        let passobjectforrootclasspayfort = OTPGenrateModel(fromJson: jsonpayfortrequest)
        print(passobjectforrootclasspayfort.transaction_id!)
        SVProgressHUD.dismiss()

    } else {
        print("error connection") SVProgressHUD.dismiss()

    }

}
ios swift sorting alamofire
1个回答
1
投票
首先,您的问题不清楚。无论如何,您可以像这样创建更简洁的字典

let product: [String: Any] = [ "product_name": getName, "product_price": getTotal, "product_category":getProductType ] print(product) // You can print this way let request: [String: Any] = [ "merchant_reference":getRandomMerchant, "merchant_identifier":"e54638eb", "access_code":"hRRVGXrIpHSYoH19Ebwt", "signature": base64Str, "service_command":"OTP_GENERATE", "language":"en", "payment_option":"VALU", "phone_number":"01008606003", "merchant_order_id":getRandomMerchant, "amount":getTotal, "currency":"EGP", "products": [ product ] ]

然后将其传递给

request.setDictionary(request)

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