How do I use JSON arrays with Alamofire parameters?

前端 未结 8 1910
借酒劲吻你
借酒劲吻你 2021-01-05 01:03

I\'m having a bit of trouble structuring my parameters so that our server API would be able to read it as valid JSON.

Alamofire uses parameters like this in swift la

8条回答
  •  臣服心动
    2021-01-05 01:31

    Taken from Alamofire's GitHub page:

    let parameters = [
        "foo": [1,2,3],
    "bar": [
        "baz": "qux"
    ]
    ]
    
    Alamofire.request(.POST, "http://httpbin.org/post", parameters: parameters, encoding: .JSON)
    // HTTP body: {"foo": [1, 2, 3], "bar": {"baz": "qux"}}
    

    EDIT: And from your example:

    let parameters = [
        "string": "str",
    "params": [[
        "param1" : "something",
        "param2" : 1,
        "param3" : 2,
        "param" : false
    ],[
        "param1" : "something",
        "param2" : 1,
        "param3" : 2,
        "param" : false
    ]
    ]
    ]
    

提交回复
热议问题