我在邮递员中有原始格式的json数据,我想在我的快速代码中使用使用alamofire的post方法。参数格式如下:
{
"customer": {
"email": "[email protected]",
"firstname": "xxxx",
"lastname": "r",
"middlename": ""
},
"password": "xxxxxxx"
}
如何在我的代码中快速将其作为参数传递。我已经尝试过
let parameters: [String: String] =
[
"customer": [
"email":self.emailTxt.text!,
"firstname":self.fnameTxt.text!,
"lastname":self.lnameTxt.text!,
"middlename":"test"
],
"password": self.PassTxt.text!
]
这似乎显示错误。让我知道如何传递这些参数。
将参数字典更改为Alamofire参数
let customer : Parameters = [
"email":self.emailTxt.text!,
"firstname":self.fnameTxt.text!,
"lastname":self.lnameTxt.text!,
"middlename":"test"
]
let parameters: Parameters =
[
"customer": customer,
"password": self.PassTxt.text!
]
然后调用API
Alamofire.request(_url,
method: .post,
parameters: parameters,
encoding: JSONEncoding.default,
headers: headers)