title: Decoding json received from ajax in php file
body: <p>I am passing json object to my php file through ajax call.</p>
  
  <p>jQuery Syntax</p>
  
  <pre><code>$.getJSON('http:..Sample/JsonCreation.php', function(data)
  {
     //data has the json - I am trying to edit this json and then pass it to another php file through ajax and save in DB. I have successfully edited but unable to access the passed json in my php file.
     questionsArray = data;
  }
  $('form').on('submit', function(event)
  {
  //AJAX CALL
                  $.ajax
                  ({
                      url: "updateTestReport.php",
                      type: "post",
                      //JSON.stringify
                      data: {json:(questionsArray)},
                      contenttype: "application/json; charset=utf-8",
                      datatype: "text",
  
                      success: function(data)
                      {
                          //alert("success");
                          alert(data);
                      },
                      error:function()
                      {
                          alert("failure");
                      }
                  });
  });
  </code></pre>
  
  <p>PHP FILE</p>
  
  <pre><code>&lt;?php
  
  //$contentjson = file_get_contents("php://input");
  //echo $_POST['json'];
  $questionsArray = json_encode($_POST['json']);
  echo $questionsArray;
  
  
  ?&gt;
  </code></pre>
  
  <p>OUTPUT:</p>
  
  <pre><code>[{"questionNumber":"1","quesDesc":"The price of petrol has increased by 25%.By what percentage should it now be reduced to return to the original price?","optionA":"25%","optionB":"20%","optionC":"15%","optionD":null,"correctOption":"A","selectedAnswer":null,"isQuestionViewed":null},{"questionNumber":"2","quesDesc":"Price of cooking gas has increased by 10%. By what percentage should consumption be reduced to keep expenditure unchanged?","optionA":"9.09%","optionB":"10%","optionC":"11.11%","optionD":null,"correctOption":"A","selectedAnswer":null,"isQuestionViewed":null},{"questionNumber":"3","quesDesc":"A buys a shirt for Rs 100 and sells it to B for Rs 120. B now sells it to C for Rs 144. Had A sold it directly to C at the price C paid for it, then his profit % would have been","optionA":"10%","optionB":"20%","optionC":"44%","optionD":null,"correctOption":"C","selectedAnswer":null,"isQuestionViewed":null}]
  </code></pre>
  
  <p>1) How is that json_encode in the php file gives the output. Shouldn't i use json_decode? 
  2) And even through the encoded json, i am not able to retrieve the values. Please let me know how to access the values from this json...
  3) what is the difference between file_get_contents &amp; $_POST['json']?</p>
  
  <p>EDIT:
  //BEGIN</p>
  
  <p>I need to access my json inside the php file, retrieve some values, make some calculations, save in DB. Then return to the main html file.</p>
  
  <p>//END
  Kindly give clear explanation...</p>