如何使用alamofire将多个JSON对象作为流发送

如何使用alamofire将多个JSON对象作为流发送,第1张

如何使用alamofire将多个JSON对象作为流发送

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) }    }


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5615292.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存