Simple example of PHP receiving post data and parsing json

Source: Internet
Author: User
Tags php json
Simple example of PHP receiving post data and parsing json
This article introduces an example of php receiving post data and parsing json for your reference.

Php receives post data, parses json code, and uses the php functions stripslashes, json_decode, and var_dump:

     

Code description: first, get the value of the POST form field txt_json in the html file, put it in the variable $ json_string, and then make a judgment. if the current PHP is set to magic_quotes_gpc = On, that is, the passed double quotation marks will be escaped, so that the json_decode function cannot be parsed, so it needs to be reversed. After the definition is reversed, the json_decode function is used to convert the JSON text into an object and save it in the $ user variable. echo var_dump ($ user); is used to output the dump of the object.

Appendix: php json data parsing code

PHP parses JSON data code. it always knows how to parse various transfer formats of API data, including JSON and XML. Run the following code to parse the data obtained from POST on A Renren website:

     name; //prints fooecho $obj->interest[1]; //prints php?>

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.