Use PHP to receive POST data and parse json data

  • 2020-06-22 23:56:32
  • OfStack


<?php
 $json_string = $_POST["txt_json"];
 if(ini_get("magic_quotes_gpc")=="1")
 {
  $json_string=stripslashes($json_string);
 }
 $user = json_decode($json_string);
 echo var_dump($user);
?>

In this file, we first get the value of the POST form field txt_json in the html file, put it in the variable $json_string, and then determine that if the current setting of PHP is magic_quotes_gpc=On, the passed double quotes will be escaped, so the json_decode function cannot be resolved, so we want to unescape it. Then, use the json_decode function to convert the JSON text into an object, store it in the $user variable, and finally use echo var_dump($user). , output the object dump


Related articles: