但我想能够发送以下示例Json:
[ "06786984572365","06644857247565","06649998782227"]你可以用NSJsONSerialization编码JsON,然后自己生成NSURLRequest。例如,在Swift 2:
let request = NSMutableURLRequest(URL: url)request.httpMethod = "POST"request.setValue("application/Json",forhttpheaderFIEld: "Content-Type")let values = ["06786984572365","06649998782227"]request.httpBody = try! NSJsONSerialization.dataWithJsONObject(values,options: [])Alamofire.request(request) .responseJsON { response in // do whatever you want here switch response.result { case .Failure(let error): print(error) // if web service reports error,sometimes the body of the response // includes description of the nature of the problem,e.g. if let data = response.data,let responseString = String(data: data,enCoding: NSUTF8StringEnCoding) { print(responseString) } case .Success(let responSEObject): print(responSEObject) }}
或者,在Swift 3:
var request = URLRequest(url: url)request.httpMethod = "POST"request.setValue("application/Json","06649998782227"]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,enCoding: .utf8) { print(responseString) } case .success(let responSEObject): print(responSEObject) }}总结
以上是内存溢出为你收集整理的swift – 通过Alamofire发送json数组全部内容,希望文章能够帮你解决swift – 通过Alamofire发送json数组所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)