[英]Alamofire put with array of ObjectMapper
I have array of ObjectMapper
: 我有
ObjectMapper
数组:
var arr = [Model]
now how can i use Alamofire
to send this array to server with .PUT
or .POST
method? 现在如何使用
Alamofire
使用.PUT
或.POST
方法将此数组发送到服务器?
Alamofire.request(.PUT, Config().apiGroup, parameters: arr, encoding: .JSON)
it says that parameters type is [String : AnyObject]?
它说参数类型是
[String : AnyObject]?
. 。
I tried with this too: 我也尝试过这个:
var params = Array<AnyObject>()
for entry in arr {
params.append(Mapper().toJSON(entry))
}
and then to pass params
to parameters
, but still getting error. 然后将
params
传递给parameters
,但仍然会出错。
Any solution? 有什么办法吗?
You can do this to convert: 您可以执行以下转换:
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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.