我的问题是如何在Alamofire中的参数中发送Int ([1,2,3,4])
数组。我的数组不是JSON格式,而是Int数组,因为服务器希望此([1,2,3,4])
没有任何键。
如何在我的代码中如何在Alamofire参数的function参数中发送"userInfos:[Int]"
?
func putPreferences(workId: String, userInfos:[Int] ) {
let token = NSObject.getValueForKey(key: "userToken") as! String
let headers: HTTPHeaders = [
"Authorization" : token,
"Content-type" : "application/json"
]
let jsonEncoder = JSONEncoder()
let jsonData = try? jsonEncoder.encode(userInfos)
let json = (try? JSONSerialization.jsonObject(with: jsonData!, options: [])) as? [String:AnyObject]
print(json)
let url = "URL"
print(url)
Alamofire.request(url, method: .put, parameters: json , encoding: JSONEncoding.default, headers: headers)
.validate(statusCode: 200..<501)
.responseJSON { response in
switch response.result {
case .success(let data):
if (response.response?.statusCode)! <= 300{
print(data)
}
else{
print(data)
print("error")
}
case .failure(let error):
// self.signupDelegtae?.signUpFailed()
print(error)
}
}
}