We first create a form in HTML, and submit the client's json data to the server through this form. (Recommended learning: PHP programming from entry to proficiency)
In a button event, we first define an object variable and then use JSON.stringify Method converts the object into a json string.
Then assign the json string to the hidden input box of the form. Submit the form again.
In the PHP code, we can use the global POST variable to obtain the data submitted by the client.
If we run the page according to the above code, the output we get is a string, so it is very inconvenient to use this json string in php of.
In fact, we can use php's json_decode method to convert the obtained json string back to an object array.
The output on the page here is an array of objects. As you can see from here, it is very convenient for us to use this object array. For example, to obtain the text field of the object, we can use $json_data['text'] to obtain it.
The above is the detailed content of How to use the json data obtained by php. For more information, please follow other related articles on the PHP Chinese website!