title: Codeigniter - array of json objects in post
body: <p>In fire bug I view my jquery post request parameters, its like this</p>
  
  <pre><code>adults            1
  applicants[]    [object Object]
  attendees   1
  children    0
  </code></pre>
  
  <p>In this post request the array called <strong>applicants</strong> contains json object which I want ti iterate over and pull out values in my codeigniter controller. The json string may look like this</p>
  
  <pre><code>({attendees:"2", 
    adults:"2", 
    children:"0", 
    grptype:"2", 
    'applicants[]':[{firstname:"John", lastname:"Doe", age:"33", allergies:"true", diabetic:"true",    lactose:"false", note:"nuts"}, {firstname:"Jane", lastname:"Doe", age:"34", allergies:"true", diabetic:"false", lactose:"false", note:"pollen"}]
  })
  </code></pre>
  
  <p>Look at the applicants[] above, see I have info for two people as a json object. I am not sure how access the data in my controller. see this</p>
  
  <pre><code>$applicants = $this-&gt;input-&gt;post('applicants');
  $this-&gt;output-&gt;append_output("&lt;br/&gt;Here: " . $applicants[0].firstname );
  </code></pre>
  
  <p>I was thinking $applicants[0] woild refer to the json object and I could just pull outs values on demand. Not sure hat I am doing wrong. Thanks guys.</p>
  
  <p><strong>EDIT</strong>
  So I have adjusted my json and it looks like this</p>
  
  <pre><code>adults  2
  applicants[]    {firstname:"John", lastname:"Doe", age:"23", allergies:"true", diabetic:"true", lactose:"false", note:"nuts"}
  applicants[]    {firstname:"Jane", lastname:"Doe", age:"23", allergies:"false", diabetic:"false", lactose:"false", note:""}
  attendees   2
  children    0
  </code></pre>
  
  <p>Now I am still getting an error saying </p>
  
  <pre><code>**Message: json_decode() expects parameter 1 to be string, array given**
  </code></pre>
  
  <p>Any ideas ?</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Ok mu data now liiks like this</p>
  
  <pre><code>adults  1
  applicants[]    {"firstname": "John", "lastname": "Doe", "age": "34", "allergies": "true", "diabetic": "true", "lactose": "false", "note": "nuts"}
  attendees   1
  children    0
  </code></pre>
  
  <p>In the controller id did this</p>
  
  <pre><code>$applications = $this-&gt;input-&gt;post('applicants');
  foreach ( $applications as $item)
  {
    $item = json_decode($item, true);  
    $this-&gt;output-&gt;append_output(print_r($item));
  }
  </code></pre>
  
  <p>This is the result of that logic</p>
  
  <pre><code>Array
  (
      [firstname] =&gt; John
      [lastname] =&gt; Doe
      [age] =&gt; 34
      [allergies] =&gt; true
      [diabetic] =&gt; true
      [lactose] =&gt; false
      [note] =&gt; nuts
  )
  </code></pre>
  
  <p>Not sure what I am doing wrong, no matter what I do to access the dater I get an error to the effect that I cannot access it like that. How do I pull out the values ?</p>