0

I need to pass an array of string/Int (doesnt matter) as JSON parameter in a HTTP body for a POST request.

{
  "par1" : value,
  "par2" : "value2",
  "par3" : ['123:456', '123:234' ...]*
}

*My problem is for filling my JSON object with param3 values. In the swift code I have them as an array of Strings.

There are many example of converting a JSON object back to an array of strings/Int, but I can't find it the other way around.

  • Check out NSJSONSeralization, it can take Swift types and encode them to JSON. – Fred Faust Mar 11 '16 at 15:43
  • 1
    Follow the example here: http://stackoverflow.com/a/29625483/2227743 The title says "dictionary" but it also works for arrays. – Eric Aya Mar 11 '16 at 15:45
  • 1
    Also this one: http://stackoverflow.com/a/31263337/2227743 – Eric Aya Mar 11 '16 at 16:02
  • I already have a WIP impl with NSJSONSerialization @thefredelement but i wish I could use a swiftyJSON solution –  Mar 11 '16 at 16:17
  • Ok so NSJSONSerialization is the way to go, I already found about this but i was hoping that swiftyJSON had something else. Thanks guys –  Mar 11 '16 at 16:18

1 Answers1

0

As mentioned in the comments, the way to go is to use NSJSONSerialization to generate object encoded in JSON data.