Alamofire: sending JSON as request parameter

I have an incredibly long array and a string that I want to send via Alamofire, although I don't know how to send raw JSON as a parameter. JSON is a bit like

{
     "skus":["8865594-CS,4387296-CS,1175540-CS...."],
     "listType": "H"
}

      

Instead of making this behave like a Swift array and then serializing it, is there a way to pass this JSON as a parameter to Alamofire?

Thank!

Edit:

I was able to pull a little magic in a text editor to get the parameters formatted in a Swift array style (as in var skus = ["abc", ...]

), so I did skus

it listType

in a dictionary too, as advised by Eric. This worked well enough, except I got the status code: 414, which means the URL is too long.

0


source to share


1 answer


I don't know Alamofire, but I just searched for it and found something in my ReadMe on GitHub ....

let parameters = [
    "foo": "bar",
    "baz": ["a", 1],
    "qux": [
        "x": 1,
        "y": 2,
        "z": 3
    ]
]

Alamofire.request(.POST, "http://httpbin.org/post", parameters: parameters)
// HTTP body: foo=bar&baz[]=a&baz[]=1&qux[x]=1&qux[y]=2&qux[z]=3

      

https://github.com/Alamofire/Alamofire



Here you have a dictionary (dictionary as JSON) and also a parameter with another dictionary (JSON) as the parameter value ...

This is what you need?

+4


source







All Articles