使用Alamofire在Swift 4 ios中将Json对象作为参数值发布
我尝试了很多方法,但每次都失败了。 我想将json对象作为键值发布 关键是“数据” 关键值是使用Alamofire在Swift 4 ios中将Json对象作为参数值发布,swift,post,alamofire,Swift,Post,Alamofire,我尝试了很多方法,但每次都失败了。 我想将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","qu
{"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;
{
message = "successfully submitted";
status = successful;
}
但通过邮递员,我得到了以下回应
{
message = "Please Try After Some Time";
status = error;
{
message = "successfully submitted";
status = successful;
})
我尝试了很多方法,但都没有成功。请给我你有价值的建议
谢谢**这是通过使用迅捷JSON解决的。我搜索了很多网站,但没有得到预期的答案。 我张贴答案,因为它将是有用的人 解决办法是
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对象。您遇到了什么错误?我在postman中发布了相同的参数,它会给出“状态:“成功”的响应,但通过上述代码,获取状态错误请在您的问题中添加您的错误。没有错误,它没有给出成功的回应