Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

how to set JSON array for the json request body #13

Closed
ruiyang2012 opened this issue Sep 1, 2015 · 1 comment
Closed

how to set JSON array for the json request body #13

ruiyang2012 opened this issue Sep 1, 2015 · 1 comment

Comments

@ruiyang2012
Copy link

the signature for ajax call's json body is [String:AnyObject?], I need to post a JSON array to the server, how can I do that, will JustHTTP support that use case?

@dduan
Copy link
Owner

dduan commented Sep 1, 2015

@ruiyang2012 the signature is [String:AnyObject]?, different from what you posted.

Unfortunately, there's no convenient way to send an JSON array. The requestBody parameter allows you to construct the request body directly, so you can send your JSON array this way:

if let body = try? NSJSONSerialization.dataWithJSONObject([1,2,3], options: NSJSONWritingOptions(rawValue: 0)) {
    Just.post("http://httpbin.org/post", headers:["content-type":"application/json"], requestBody: body)
}

There might be a case to change the type of json here. I'll need to see how common the use case such as yours is.

@dduan dduan closed this as completed Sep 2, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants