Use PHP to receive post data and parse JSON data

Source: Internet
Author: User
Tags json
This article is the use of PHP to receive post data and JSON data for a detailed analysis of the introduction, the need for friends to copy the Code code below:
<?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 judge if the current PHP is set to Magic_quotes_gpc=on, that is, the incoming double quotes will be escaped so that Json_ The Decode function cannot parse, so we want to invert it. Then, use the Json_decode function to convert the JSON text to an object, save it in a $user variable, and end up with the Echo var_dump ($user);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.