我正尝试在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