我试图使用Alamofire在swift中使用正文数组发布帖子请求
邮递员喜欢这里是我的代码
class func storeEventContact(_ id:String, type_contact:String, user_id: Int, firstname:String, lastname: String,completionHandler:RequestCompletionHandler?){
let url = "\(Endpoints.BASE)\(Endpoints.INVITE_STORE)"
let params:NSMutableDictionary? = ["id": id,
"type_contact":type_contact,
"contacts": ["user_id" : user_id, "firstname" : firstname, "lastname" : lastname]]
self.postRequest(url: url, parameters: params as? [String : Any]) { (result, error) in
self.postRequest(url: url, parameters: params as? [String : Any]) { (result, error) in
if error != nil{
completionHandler?(result, error)
return
}
let baseResponse = Mapper<BaseResponse>().map(JSONObject: result)
if !baseResponse!.status{
completionHandler?(baseResponse, error)
return
}
completionHandler?(result, error)
}
}
}
答案 0 :(得分:4)
你只需要定义一个数组,你几乎就在那里,只需要在你的字典中增加一组[]
。
let params = ["id": id,
"type_contact":type_contact,
"contacts": [
[
"user_id": user_id,
"firstname": firstname,
"lastname": lastname
]]]