我没有得到如何将此类数据发布到webservice
{
"customer_id":"",
"customer_message": " entered by user",
"discount_amount": "",
"ip_address":"1.0.10.22",
"billing_address": {
"first_name": "hello",
"last_name": "world",
"company": "",
"street_1": "45 W test",
"street_2": "",
"city": "London",
"state": "Texas",
"zip": "123456",
"country": "United States",
"country_iso2": "US",
"phone": "",
"email": "xyz@example.com"
},
"shipping_addresses": [
{
"first_name": "rest",
"last_name": "Mctest",
"company": "Test Address",
"street_1": "rest test",
"street_2": "",
"city": "test",
"state": "test",
"zip": "12345",
"country": "United States",
"country_iso2": "US",
"phone": "",
"email": "xyzer@example.com"
}
],
"products": [
{
"product_id": 5448,
"quantity": 2
}
]
我没有得到如何将这种类型的数据发布到webservice中。 请帮帮我
我正在做这种类型的数据现在我必须发布这种类型。任何人都可以发布此类型。
let aParam = ["email": Email, "password":Password] as [String:Any]
答案 0 :(得分:1)
您将参数设为[String: Any]
,其中Any表示每种类型的数据类型。说字符串,数组和字典。
例如,
let aParam: [String: Any] = ["customer_id": "",
"customer_message": "",
"billing_address": ["first_name" : "hello",
"last_name" : "world",
"company" : "",
"street_1" : "45 W test"],
"shipping_addresses": [
["first_name" : "hello",
"last_name" : "world",
"company" : "",
"street_1" : "45 W test"]
],
"products": [
["product_id" : 5448,
"quantity" : 2],
["product_id" : 5450,
"quantity" : 1]
]
]
复杂的json结构将作为JSON处理内容类型,所以:
您只需将标题更新为:
let aHeader = ["Content-Type" : "application/json"]
希望这会有所帮助