Alamofire在参数中发送字典数组

时间:2018-02-08 08:09:03

标签: ios alamofire swift4

我有一个POST API,其中我发送了多个参数,其中一个参数必须是array dictionaries

let arr = [
    [
        "id" : "1",
        "price" : "10"
    ],
    [
        "id" : "2",
        "price" : "20"
    ]
]
let params : Parameters = [

    "param1" : "anyvalue1",

    "param2" : "anyvalue2",

    "param3" : arr,

    ]

当我在Alamofire Request中使用这些参数并点击API时,print(res.result.value)始终返回未知。谁能帮我这个。以下是请求API的方式

Alamofire.request(url, method:.post, parameters: params).responseJSON{(res) in print(res.result.value) //always shows 'unknown' as output }

1 个答案:

答案 0 :(得分:0)

尝试使params成为[String:Any]的Dic:

let params : [String:Any] = [

    "param1" : "anyvalue1",

    "param2" : "anyvalue2",

    "param3" : arr,

    ]