title: Unable to use $.parseJSON on string variable constructed with array variable
body: <p>I'm able to successfully parse a variable manually initialized with JSON using jQuery's '$.parseJSON();' but I cannot parse a variable with identical JSON format that was constructed using an array.</p>
  
  <p>Javascript</p>
  
  <pre><code>var questionstype = [];
  var questionshtml = [];
  var questionsquestion = [];
  //Store all questions, types, and html for each fieldset into 3 separate arrays
  for(var i=1;i&lt;=formpreviewid;i++)
    {
   questionsquestion.push($("#formelement_"+i + " legend").text());
   questionstype.push($("#formelement_"+i).attr("class"));
   questionshtml.push($("#formelement_"+i)[0].outerHTML);
    };
    //alert(questionsquestion[1] + questionstype[1] + questionshtml[1]);
  
    //format values for each fieldset into values format in mysql
    var questionsvalues = [];
    var index = 0;
    for(var i=1;i&lt;=formpreviewid;i++)
    { 
    questionsvalues.push('{"question":"'+questionsquestion[index]+'","type":"'+questionstype[index]+'","html":"'+questionshtml[index]+'"}');
    index++;
    };
    //alert(questionsvalues);
  //questionsvalues = questionsvalues.replace("}{", "},{");
  //alert(questionsvalues);
  
   //format mysql values into JSON format
   var questionsvaluesjson = '{"questions":['+questionsvalues+']}';
  </code></pre>
  
  <p>Using manually constructed string variable with identical JSON format --</p>
  
  <pre><code> var questionsquestion2 = '{"questions":[{"question":"test16","type":"radio", "html":"&lt;input&gt;"},{"question":"test2","type":"checkbox", "html":"&lt;input&gt;"},{"question":"test3","type":"checkbox", "html":"&lt;input&gt;"}]}';
  
  ParseJSON(questionsvaluesjson); //works fine
  </code></pre>
  
  <p>Using string constructed from array --</p>
  
  <pre><code> var questionsvaluesjson = '{"questions":['+questionsvalues+']}';
  
   Alert(questionsvaluesjson) :
  
   {"questions":[{"question":"d","type":"radio","html":"&lt;fieldset id="formelement_1" class="radio"&gt;&lt;tr&gt;&lt;td colspan="2"&gt;&lt;legend&gt;d&lt;/legend&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;label for="1_1"&gt;d&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input name="radio1" value="d" type="radio"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;label for="1_2"&gt;d&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input name="radio1" value="d" type="radio"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/fieldset&gt;"}]}
  
   ParseJSON(questionsvaluesjson); //Breaks script
  </code></pre>
  
  <p>I am sending this JSON to a php file to be decoded and then used in a foreach loop where I can manipulate the objects to insert the data into a mysql database, but currently it is throwing an error when trying to use object in foreach loop.</p>
  
  <p>Here is the error : 'Trying to get property of non-object'</p>
  
  <p>Here is the code :</p>
  
  <p>PHP</p>
  
  <pre><code>foreach ($theArray-&gt;questions as $data)
  {   
    $insert .= '("' . $data-&gt;question . '", "' . $data-&gt;type . '", "' . $data-&gt;html . '")';
  }
  $insert = str_replace(")(","),(",$insert);
  
  $query = "INSERT INTO registrationquestions (question, type, html) VALUES " . $insert; 
  $mysqli-&gt;query($query);
  </code></pre>