gpt4 book ai didi

swift - 使用 Alamofire 在 Swift 4 ios 中将 Json 对象作为参数值发布

转载 作者:行者123 更新时间:2023-11-30 11:16:11 26 4
gpt4 key购买 nike

我尝试了很多方法,但每次都失败了。我想将 json 对象作为键值发布关键是“数据”键值为

{"totalcost":"8500","delivery_type":"take_away","order_name":"","order_mobilenumber":"","order_city":"Chose Your Place","order_address":"","take":"  2 Hour ","":[{"parent_id":"145","subitem_id":"179","quentity":"1"}],"customer_id":"6"}

我的代码是

let parameters: [String: Any] = [
"data":
["customer_id":"6",
"totalcost":"8500",
"delivery_type":"take_away",
"order_name":"",
"order_mobilenumber":"",
"order_city":"Chose Your Place",
"order_address":"",
"take_away_time":" Next 2 Hour ",
"":[
[
"parent_id":"145",
"subitem_id":"179",
"quentity":"1"
]
]
]

]

Alamofire.request("http:/app_con",method:.post,parameters:parameters,encoding:JSONEncoding.default).responseJSON{response in
let jsonResult = response.result.value
print(jsonResult)

}

我收到的回复低于

{
message = "Please Try After Some Time";
status = error;

}

但是通过 postman 我得到了以下回复

{
message = "successfully submitted";
status = successful;

})

我尝试了很多方法,但没有任何效果。请给我您宝贵的建议。

谢谢

最佳答案

**使用 SwiftyJson 解决了这个问题。我搜索了很多网站,但没有得到预期的答案。我发布答案是因为它对某人有用

解决方案是

I tried to post key value in dictionary format instead of json format,That's why i did not get expected output. swiftjson is very to write json object.**

let emptyJson : JSON = JSON(["customer_id":"26",
"totalcost":"8500",
"delivery_type":"take_away",
"order_name":"",
"order_mobilenumber":"",
"order_city":"Chose Your Place",
"order_address":"",
"take_away_time":" Next 2 Hour ",
"":[
[
"parent_id":"145",
"subitem_id":"179",
"quentity":"1"
]
]
])
let parameters: [String: Any] = [
"data": emptyJson
]
Alamofire.request("http://_con",method:.post,parameters:parameters).responseJSON{response in
let jsonResult = response.result.value
print(jsonResult)

}

并且不需要在 Alamofire 请求中使用 json 编码。我们只是发布 json 对象。

关于swift - 使用 Alamofire 在 Swift 4 ios 中将 Json 对象作为参数值发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51721400/

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