Home  >  Article  >  Backend Development  >  How to use the json data obtained by php

How to use the json data obtained by php

(*-*)浩
(*-*)浩Original
2019-09-25 14:18:483062browse

How to use the json data obtained by php

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)

How to use the json data obtained by php

In a button event, we first define an object variable and then use JSON.stringify Method converts the object into a json string.

How to use the json data obtained by php

Then assign the json string to the hidden input box of the form. Submit the form again.

How to use the json data obtained by php

In the PHP code, we can use the global POST variable to obtain the data submitted by the client.

How to use the json data obtained by php

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.

How to use the json data obtained by php

In fact, we can use php's json_decode method to convert the obtained json string back to an object array. How to use the json data obtained by php

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.

How to use the json data obtained by php

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!

Statement:
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