Get the App
SLTechnology News&Howtos  ›  Development  › 

Operation instructions of JSON data in PHP

Shulou Source: shulou.com Published: 2022-06-03 19:58:32 09月16日 Update

This article mainly explains "JSON data operation instructions in PHP". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "JSON data operation instructions in PHP"!

JSON, full name is JavaScript Object Notation. It is a lightweight data exchange format based on the JavaScript programming language ECMA-262 3rd Edition-December 1999, which is mainly used to exchange data with the server. Similar to XML, it is independent of language and has great advantages in cross-platform data transmission.

To create a new file json.php, do the encode operation first:

/ / encode / / generate data in JSON format $arr = array (1, arr 2, 3, 4, 5, 6, 7, 8, 9); echo json_encode ($arr); / / json_encode: converts an object into PHP format data

The result is [1, Hello, 3, 4, 5, 6, 7, 8, 9, "Hello", "PHP"]

Then do the decode operation:

/ / decode decode $jsonStr ='{"h": "Hello", "w": "World", "0": [3Jing 2je 1]}'; $obj = json_decode ($jsonStr); echo $obj- > hbank / the result can be obtained by using the member visit method.

After knowing the simple way to use it, you can try to capture API data, such as the weather.

At this point, I believe you have a deeper understanding of the "JSON data operation instructions in PHP". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Data operating instructions format content method result language learning practical large deeper advantage usage full name interest weather practicality actual object member Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information Docker MySQL NVidia