ios - Alamofire:发送参数

标签 ios swift3 alamofire

我想将数据作为参数发布,如下所示:

{ 
    "data":
    [
        {
            "nik" : "lalaal"
        }
    ]
}

如何使用 Alamofire 在 Swift 3 中写入这些参数?

我尝试过:

let parameter: Parameters = [
                "data":[[
                    "nik" : self.nik,
                    "check_type" : "IN",
                    "tanggal" : "01-08-2017 18:22:00",
                    "long" : String(locationList[projectChoosen].long!),
                    "lat" : String(locationList[projectChoosen].lat!),
                    "id_loc" : locationList[projectChoosen].id_project,
                    "id_project" : nil,
                    "nama_project" : locationList[projectChoosen].nama_project,
                    "barcode" : "",
                    "foto": "",
                    "mime_type" : "image/jpeg"

                    ]]
            ]

最佳答案

您可以使用下面的代码。

let dicRequest: NSDictionary = ["userid" : "test", "password" : "test123"]

let postParams:NSDictionary = [
    "data": dicRequest
]
let requestURL: String = String(format: "%@/Login", serverURL)
Alamofire.request(requestURL, method: .post, parameters: postParams as? [String : AnyObject], encoding: JSONEncoding.default, headers: [:])
    .responseJSON { response in switch response.result {

    case .success(let JSON):
        print("response :-----> ",response)
    case .failure(let error):
        print("Request failed with error: \(error)")

        }
}

关于ios - Alamofire:发送参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45437078/

相关文章:

iphone - 比较两个数组的问题

ios - 实时混合 UIImages

ios - Swift 3 中的 UICollectionView 自定义按钮操作

ios - 如何创建像 Alamofire Responses 这样的 block 响应?

arrays - SwiftyJson - 从数组中删除空元素

ios - 使用自定义对象 ios 键入 Cast

ios - 无法启动应用程序(验证开发者应用程序证书)

json - Swift 到 Swift 3 代码转换 : Reading JSON files

swift3 - 快速获得两次之间的时差3

ios - 如何遍历 JSON 坐标并将注释构建为一个函数?