我正嘗試在POST API中發送字典。爲此我使用Alamofire。如何使用Alamofire Swift中的數組發送字典
參數字典如下:
var param: Dictionary<String, AnyObject> =
[
"name" : name,
"email" : email,
"mobile_number" : mobile_number,
"body" : body
] as Dictionary<String, AnyObject>
param["listing_ids[]"] = [772121,772136,772129]
發送請求到服務器如下:
Alamofire.request(.POST,baseUrl+enquiryEndPoint , parameters: params , encoding: .URL, headers: createHeader()).responseJSON { response in
switch response.result {
case .Success:
guard let response = response.result.value as? Dictionary<String, AnyObject> else{return}
completionBlock(response,error: nil)
case .Failure(let error):
completionBlock([:],error: error)
}
}
時打印參數字典,誤差如下:
["mobile_number": 457823356, "email": [email protected], "body": Hello, I found your property on <country-website>. Please send me additional information about this property.
Thank you, "listing_ids[]": <_TtCs21_SwiftDeferredNSArray 0x1400d6ff0>(
708783,
589915,
722173,
746261,
618410
)
, "name": s]
值對應於鍵「listing_ids []」是一個Int數組。這在這裏引起問題。
某些「_TtCs21_SwiftDeferredNSArray」寫在那裏對我來說完全不清楚。
由於我得到空白的迴應。
請幫幫我。
你解決了這個問題嗎? –
@AnandPrem是的我已經解決了這個問題,通過升級Alamofire版本爲SWIFT 3.0 – Sunita