gpt4 book ai didi

ios - 如何在 Alamofire 请求 swift 3 中传递 JSON 对象

转载 作者:行者123 更新时间:2023-11-28 19:31:12 25 4
gpt4 key购买 nike

我正在使用 Alamofire API 进行服务调用。到目前为止,GET 方法运行良好。现在我需要执行一个 PUT 请求。它还接受这种类型的主体参数。

{
"LeaveEntryCode":0,
"RequestId":0,
"EmployeeCode":17227,
"LeaveYear":2017,
"LeaveTypeCode":1,
"LeaveReasonCode":1,
"BaseType":"ess",
"StartDate":"2017-06-16T00:00:00",
"EndDate":"2017-06-16T00:00:00",
"NoOfDays":1.0,
"StartDateSession":"full",
"EndDateSession":"full",
"PreApproved":false,"ForDate":"1901-01-01T00:00:00",
"Remarks":"I have to attend for a wedding of my close relatives",
"CoveringPersonCode":0,
"RequestStatus":"P",
"Deleted":false,
"Status":false,
"CreatedBy":0,
"CreatedDate":"0001-01-01T00:00:00",
"UpdatedBy":0,
"UpdatedDate":"0001-01-01T00:00:00",
"DeletedBy":0,
"DeletedDate":"0001-01-01T00:00:00",
"ModuleId":2,
"ObjectId":20,
"StartDateString":"06/16/2017",
"EndDateString":"06/16/2017",
"LeaveDayList":["06/16/2017-FH,06/16/2017-SH"],
"SystemLeaveTypeCode":"ANN",
"LeaveTypeName":"ANNUAL",
"Employee":null,
"LieuDayList":null,
"BaseLeaveType":"ANN",
"CoveringPersonName":"",
"LeaveReasonName":"Personal",
"DocumentSource":"LEAVE",
"AttachedDocument":null
}

我创建了一个 [String:Any] 对象并分配给以下请求中的 parameters

But I got an error called Extra argument 'method' in the call.

但是如果我将它分配为 ["":""] 错误就会消失。我该如何解决这个问题?请帮助我。

Alamofire.request(urlString, method: method, parameters: parameters, encoding: JSONEncoding.default, headers: headerToken)

更新

var dictionary:[String:String]!
dictionary=[
"LeaveEntryCode":"0",
"RequestId":dm.strReqID,
"EmployeeCode":dm.strEmpCode,
"LeaveYear":dm.selectedYear,
"LeaveTypeCode":dm.selectedLeaveTypeCode,
"BaseType":"ess",
"StartDate":dm.startDate,
"EndDate":dm.endDate,
"NoOfDays":dm.noOFDays,
"StartDateSession":dm.startDateSession,
"EndDateSession":dm.endDateSession,
"RequestStatus":"P",
"PreApproved":"0",
"ForDate":"01/01/1901",
"Remarks":comment,
"CoveringPersonCode":dm.strcoveringPersonCode,
"LeaveDayList":strDayLvList,
"BaseLeaveType":dm.selectedLeaveTypeCode,
"LeaveReasonCode":dm.selectedReasontypeCode,
"AttachedDocument":"null"
]

最佳答案

你在调用中遇到一个名为 Extra argument 'method' 的错误,这是由于 header 引起的,

尝试将 header 传递为 nil 或如下所示:

//Here param equals to your dictionary as [String :Any]

//Pass Headers as Dictionary as well.

Alamofire.request("", method: .post, parameters: param, encoding: JSONEncoding.default, headers:["" : ""])

它对我有用。

同时检查此链接: Alamofire Swift 3.0 Extra parameter in call

关于ios - 如何在 Alamofire 请求 swift 3 中传递 JSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44536129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com