0

I need the send the following data as parameter for my Alamofire request:

key: "metas"

value: [{"meta_id": 80, "quantity": 2, "add_quantity": true}]

I tried this:

 let parameters: [String: AnyObject] = ["metas" : [["meta_id" : meta_id,
                                                  "quantity" : quantity,
                                                  "add_quantity" : true]] as AnyObject]

And in my router to handle Alamofire request:

urlRequest = try URLEncoding.default.encode(urlRequest, with: parameters)

1 Answer 1

2

you need to convert your array into string then pass into your string array. here, param is string array like

param:[String:String] = [:]

var arrayImages : [JSON] = []

let strImageString = JSON(arrayImages).rawString(.utf8, options: .prettyPrinted)
param["certification_image"] = strImageString

Here, it is your request

Alamofire.request(url, method: .post, parameters: param, encoding: URLEncoding.default, headers: nil).responseSwiftyJSON(completionHandler:
            {

                if $0.result.isSuccess
                {
                    completion($0.result)
                }
                else if $0.result.isFailure
                {
                    let statusCode = $0.response?.statusCode
                    print("StatusCode : \(statusCode)")
                    if(statusCode == 500)
                    {

                    }else if(statusCode != nil)
                    {
                        completion($0.result)
                    }
                    else
                    {
                        makeToast(message:  "Somethig_went_wrong_key")
                        completion($0.result)
                    }
                }else
                {
                    makeToast(message:  "No_internet_connection_key")
                    completion($0.result)
                }
        })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.