如何在Alamofire中将json数组解析为参数?

时间:2019-05-03 08:01:44

标签: arrays arraylist parameters alamofire swifty-json

我在alamofire中尝试将json数组解析为参数,但始终无法获得响应。我试图遵循Alamofire https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md的文档,但始终失败。请帮助我,这是我的代码

let parameter : Parameters = ["nikTmp":"",
                                        "id_user":"",
                                        "no_polis":"",
                                        "nik":"",
                                        "name":"hirawan",
                                        "ms_status":2,
                                        "ms_list_product_class":[6],
                                        "files" : [[
                                            "name_file": "photo",
                                            "content_file": "jpg",
                                            "base64": "/9j/4AAQSkZJRgABAQAAAQABAAD"
                                            ],["name_file": "desc",
                                               "content_file": "jpg",
                                               "base64": "/9j/4AAQSkZJRgABAQAAAQABAAD"],
                                              [
                                                "name_file": "photoRS",
                                                "content_file": "jpg",
                                                "base64": "/9j/4AAQSkZJRgABAQAAAQABAAD"
                                            ]]]

Alamofire.request(url, method: .post, parameters: parameter, encoding: URLEncoding.default).responseJSON{
        (response) in

        switch response.result{
        case .success(let value):
            print(value)

        case .failure(let error):
            print(error)
        }
    }

这里是参数要求

{
    "nikTmp": "",
    "id_user": "",
    "no_polis": "",
    "nik": "",
    "nama": "",
    "ms_status_hubungan": 2,
    "ms_list_product_class": [
        6
    ],
    "files": [
        {
            "name_file": "photo",
            "content_file": "jpg",
            "base64": "/9j/4AAQSkZJRgABAQAAAQABAAD"
        },
        {
            "name_file": "desc",
            "content_file": "jpg",
            "base64": "/9j/4AAQSkZJRgABAQAAAQABAAD"
        },
        {
            "name_file": "photoRS",
            "content_file": "jpg",
            "base64": "/9j/4AAQSkZJRgABAQAAAQABAAD"
        }
    ]
}

0 个答案:

没有答案