gpt4 book ai didi

ios - 如何在 swift 中发送带有嵌套字典的 POST 请求

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

我在 StackOverflow 上搜索了 100 多篇帖子,但找不到任何正确答案,谁能帮我解开这个谜。

let param : [String : Any]= [
"ServiceReqID" : 1,
"WebUsersID" : customerID,
"FirstName" : userName,
"LastName" : "",
"Company" : self.profileValues.customerCompanyName,
"City" : self.profileValues.customerCityName,
"Email" : self.profileValues.customerEmail,
"ContactNo" : self.profileValues.customerContactNumber,
"Country" : "Pakistan",
"PackageChange" : 0,
"AddressChange" : 0,
"TelInternetVAS" : 0,
"Others" : 0,
"Comments" : comments,
"CSAFNO" : self.profileValues.customerCSAFNo,
"SecondaryContactNo" : "",
"CustomerTicket" : [
"RequestID" : requestID,
"TaskID" : taskID,
"Description" : comments,
"TicketTypeID" : 3,
"CustomerID" : customerID,
"PriorityID" : 3,
"CustomerTPPID" : TTPIDArray
]
]

使用此代码,只有第一个模型被发送到服务器,第二个模型通过空白值传递

func postserviceRequestFeedback (
url : String,
parameter : [String : Any],
tiket : HTTPHeaders
)
{
Alamofire.request (
url,
method : .post,
parameters : parameter,
headers : tiket
)
.responseJSON { (response) in if response.result.isSuccess{ } }

请帮助我。

最佳答案

感谢大家,我解决了这个问题。这是这个问题的逐步解决方案。1)

 Alamofire.request(url, method : .post , parameters : parameter , encoding : JSONEncoding.default, headers : tiket ).responseJSON { (response) in
if response.result.isSuccess{
let responseJoson : JSON = JSON(response.result.value!)
print(responseJoson)
}

编码在这里很重要。不要跳过这个。步骤 2)

 func apiCall(){
let customerTckt:[String:Any] = ["RequestID" : requestID ,
"TaskID" : taskID ,
"Description" : comments ,
"TicketTypeID" : 3 ,
"CustomerID" : customerID ,
"PriorityID" : 3 ,
"CustomerTPPID" : TTPIDArray ]

let param : [String : Any] = ["ServiceReqID" : 1 ,
"WebUsersID" : customerID,
"FirstName" : userName,
"LastName" : "" ,
"Company":self.profileValues.customerCompanyName ,
"City" : self.profileValues.customerCityName ,
"Email" : self.profileValues.customerEmail ,
"ContactNo" : self.profileValues.customerContactNumber ,
"Country" : "Pakistan" ,
"PackageChange" : 0 ,
"AddressChange" : 0,
"TelInternetVAS" : 0 ,
"Others" : 0 ,
"Comments" : comments ,
"CSAFNO" : self.profileValues.customerCSAFNo,
"SecondaryContactNo" : "" ,
"CustomerTicket" :customerTckt]
let userToken: HTTPHeaders = [
"Authorization": "bearer \(accessToken)",
"Content-Type": "application/json"
]
postserviceRequestFeedback(url: postRequestFeedbackUrl, parameter: param , tiket: userToken)
}

不要跳过“Content-Type”到 application/json

关于ios - 如何在 swift 中发送带有嵌套字典的 POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55371277/

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