JSON格式不适合您的请求,JSON始终是键值对,其中key始终是
String,value是any
Object。在您的示例中,需要
Array为以下类型的对象设置顶级密钥:
let SendParams = [ "key" :[["a":1234, "b":2345, "c":3456], ["a":2345, "b":3456, "c":4567], ["a":3456, "b":4567, "c":5678]] ]_ = Alamofire.request(url, method: .post, parameters: SendParams, encoding: JSONEncoding.default, headers: headers).responseJSON { (response) in}
要么
连载阵列和作为集
httpBody的
URLRequest对象:
let url = YOUR_POST_API_URL var request = URLRequest(url: URL(string: url)!) request.httpMethod = "POST" request.setValue("application/json", forHTTPHeaderField: "Content-Type") let values = [ ["a":1234, "b":2345, "c":3456], ["a":2345, "b":3456, "c":4567], ["a":3456, "b":4567, "c":5678] ] request.httpBody = try! JSONSerialization.data(withJSONObject: values) Alamofire.request(request) .responseJSON { response in // do whatever you want here switch response.result { case .failure(let error): print(error) if let data = response.data, let responseString = String(data: data, encoding: .utf8) { print(responseString) } case .success(let responseObject): print(responseObject) } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)