gpt4 book ai didi

ios - Alamofire 放入 ObjectMapper 数组

转载 作者:行者123 更新时间:2023-11-28 08:54:26 26 4
gpt4 key购买 nike

我有 ObjectMapper 数组:

var arr = [Model]

现在如何使用 Alamofire 通过 .PUT.POST 方法将此数组发送到服务器?

Alamofire.request(.PUT, Config().apiGroup, parameters: arr, encoding: .JSON)

它说参数类型是[String : AnyObject]?

我也试过这个:

var params = Array<AnyObject>()
for entry in arr {
params.append(Mapper().toJSON(entry))
}

然后将params传给parameters,还是报错。

有什么解决办法吗?

最佳答案

您可以这样做来转换:

    var request = URLRequest(url: URL(string: url)!)
request.httpMethod = HTTPMethod.post.rawValue
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

let pjson = attendences.toJSONString(prettyPrint: false)
let data = (pjson?.data(using: .utf8))! as Data

request.httpBody = data

Alamofire.request(request).responseJSON { (response) in


print(response)

}

关于ios - Alamofire 放入 ObjectMapper 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33506977/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com