Reputation: 1347
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)
Upvotes: 0
Views: 597
Reputation: 181
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)
}
})
Upvotes: 2