使用Alamofire的POST参数

时间:2018-02-18 08:04:08

标签: swift alamofire

这是POST服务器的参数模型:

{"SOSApplicant":{"Vehicles":[{"CarModelID":3299,"ChassisNO":"","Color":"قرمز","VehiclePlateP1":"22","VehiclePlateP2":"الف","VehiclePlateP3":"222","VehiclePlateP4":"22"}],"FirstName":"سینا","LastName":"اکبربان"},"PendingToken":"77398284-dec1-4472-a940-eeb564398d6d"}

我使用Alamofire发送帖子并在let ParamToSend:Parameters = ["SOSApplicant":["FirstName":"\(self.FName)", "LastName":"\(self.LName)","Vehicles":["CarModelID":self.ModelId,"ChassisNO":"\(chasisTextField.text!)","Color":"\(self.carColorTextField.text!)","VehiclePlateP1":"\(firstPelakTextField.text!)","VehiclePlateP2":"\(secondPelakTextField.text!)","VehiclePlateP3":"\(thirdPelakTextField.text!)","VehiclePlateP4":"\(fourthPelakTextField.text!)"]] ,"PendingToken":"\(token)"]中创建此参数 但服务器发送错误400 如何创建这个参数??

1 个答案:

答案 0 :(得分:0)

您的服务器需要一个Vehicles数组,并且您正在传递一个Vehicle字典。

试试这个。

let ParamToSend:Parameters = ["SOSApplicant":["FirstName":"\(self.FName)", "LastName":"\(self.LName)",
"Vehicles":[
    ["CarModelID":self.ModelId,"ChassisNO":"\(chasisTextField.text!)","Color":"\(self.carColorTextField.text!)","VehiclePlateP1":"\(firstPelakTextField.text!)","VehiclePlateP2":"\(secondPelakTextField.text!)","VehiclePlateP3":"\(thirdPelakTextField.text!)","VehiclePlateP4":"\(fourthPelakTextField.text!)"]
]] ,"PendingToken":"\(token)"]