Use PHP to receive POST data and parse json data_PHP tutorial

WBOY
Release: 2016-07-21 15:02:04
Original
737 people have browsed it

Copy code The code is as follows:

$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, first get the value of the POST form field txt_json in the html file, put it into the variable $json_string, and then judge , if the current PHP setting is magic_quotes_gpc=On, that is, the incoming double quotes will be escaped, so the json_decode function cannot parse them, so we need to unescape them. Then, use the json_decode function to convert the JSON text into an object, save it in the $user variable, and finally use echo var_dump($user); to dump the object out

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327950.htmlTechArticleCopy the code as follows: ?php $json_string = $_POST["txt_json"]; if(ini_get("magic_quotes_gpc ")=="1") { $json_string=stripslashes($json_string); } $user = json_decode($json_strin...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!