如何發送帶有參數的Alamofire的post請求作爲json的整數列表,即我的服務器期望一個字典,其鍵值是一個整數列表。Alamofire post請求與json編碼
我希望參數爲{「abc」:[1,2,3]}。如何快速發送此請求Alamofire的請求?
如何發送帶有參數的Alamofire的post請求作爲json的整數列表,即我的服務器期望一個字典,其鍵值是一個整數列表。Alamofire post請求與json編碼
我希望參數爲{「abc」:[1,2,3]}。如何快速發送此請求Alamofire的請求?
您是否嘗試過以下方法?
var parameter = ["abc": [1,2,3]]
Alamofire.request(.POST, "http://www.yoursite.com/api" , parameters:parameter)
我也會看看Alamofire github documentation的文檔,這真的很有幫助。
來自官方文檔的其他解決方案。
let parameters = [
"foo": "bar",
"baz": ["a", 1],
"qux": [
"x": 1,
"y": 2,
"z": 3
]
]
Alamofire.request(.POST, "http://httpbin.org/post", parameters: parameters)
// HTTP body: foo=bar&baz[]=a&baz[]=1&qux[x]=1&qux[y]=2&qux[z]=3
我不知道如何在自己的服務器上的後臺檢查您的數據,但我想你可以檢查你的ABC數據結果像一個字符串[1,2,3]
let parameters = [
"abc": "[1,2,3]"
]
]
你的答案不使用json編碼 –
[Alamofire:發送JSON作爲請求參數]的可能重複(http://stackoverflow.com/questions/31793155/alamofire-sending-json-as-request-parameter) – cbowns
請看這裏:https://github.com/ Alamofire/Alamofire#json編碼 –