title: POST multiple json objects in Alamofire POST method - Swift/IOS
body: <p>Sorry if my question is not clear, I'll try to make myself clear with an explanation. So here is exactly what I'm trying to do, I'm trying to use Alamofire to post more than one comment (Something that my app implements and will be stored as a JSON object whenever user writes a new comment). I'm passing these JSON comments to my post routine, where I can use SwiftyJSON to extract each value. Noe the thing is I know how to set the <strong>parameters</strong> if I'm trying to authorize the user as follows,</p>
  
  <pre><code>    var parameters = [
      "userName": userName,
      "password": passwordSalt,
      "somethingElse": somethingElse
      ]
      var err: NSError?
      request.HTTPBody = NSJSONSerialization.dataWithJSONObject(parameters , options: nil, error: &amp;err)
  </code></pre>
  
  <p>it's quite straightforward until here, now comes my problem. I'm trying to use alamofire post to post multiple json objects, which <strong>should</strong> look like this</p>
  
  <pre><code>[
     {
      "comment": "my First Comment",
      "commentDate": "2014-05-13 14:30 PM",
      "isSigned": 1,
      "patientId": 2,
      "documentId": 3
      },
     {
      "comment": "my SecondComment",
      "commentDate": "2014-05-14 14:30 PM",
      "isSigned": 2,
      "patientId": 3,
      "documentId": 4
      },
     {
      "comment": "my third Comment",
      "commentDate": "2014-05-15 14:30 PM",
      "isSigned": 3,
      "patientId": 4,
      "documentId": 5
      }
   ]
  </code></pre>
  
  <p>How do I create above array/json (I'm not exactly sure on what to call this) by iterating JSON object? <strong>I know how to get the JSON values from the JSON object</strong> all I'm asking is how to create this <strong>parameters</strong> variable to hold the data like above example. Is it even possible to do this using <strong>Alamofire?</strong> (POST multiple objects at once)</p>
  
  <p>I tried a couple of ways to but they didn't work out</p>
  
  <ol>
  <li><pre><code>var dictArray = [Dictionary&lt;String, Any&gt;]
  var dict = Dictionary&lt;String, Any&gt;
  </code></pre>
  
  <p>While iterating over JSON object inserted each value in <strong>dict</strong> and appended <strong>dict</strong> to <strong>dictArray</strong>, now when I'm trying to use dictArray as parameters in .dataWithJSONObject it doesn't like the object. </p></li>
  <li><pre><code>var dict = Dictionary&lt;String, AnyObject&gt;
  var array = NSArray()
  </code></pre>
  
  <p>extracted each value by iterating over the JSON object and inserted them into <strong>dict</strong> and tried inserting <strong>dict</strong> into array. But this gives a different problem. The way it builds the objects is different from what is required, as follows.</p>
  
  <pre><code>[
     {
      comment: my First Comment,
      commentDate: 2015-05-13 13:30 PM"",
      isSigned: 1,
      patientId: 2,
      documentId: 3 
     },
     {
      comment: my Second Comment,
      commentDate: 2015-05-13 13:30 PM"",
      isSigned: 2,
      patientId: 5,
      documentId: 4 
     },
     {
      comment: my third Comment,
      commentDate: 2015-06-13 13:30 PM"",
      isSigned: 5,
      patientId: 1,
      documentId: 9 
     }
  ]
  </code></pre>
  
  <p>Here the <strong>Keys</strong> doesn't get wrapped inside quotes (Correct way: "comment", wrong way: comment).</p></li>
  </ol>
  
  <p>Did anyone try posting multiple objects, is alamofire capable of doing so? I hope I made the question clear. Sorry if this is too simple of a question to answer, I spent my whole day figuring this out but didn't work out.</p>