Как расположить массив перед отправкой запроса на alamofire в swift - PullRequest
0 голосов
/ 09 мая 2020
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()

    }

}

1 Ответ

1 голос
/ 09 мая 2020

Попробуйте этот способ, надеюсь, это решит вашу проблему. Если нет, ответьте

let parameters: [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_name": getName,
                    "product_price": getTotal,
                    "product_category":getProductType
                    ]
                ]
        ]

        Alamofire.request(URLAPi.URL_Payment_Api , method: .post, parameters: parameters, encoding: JSONEncoding.default)
            .responseJSON {  response in
                print(response)


                // Insert your code here
        }
...