: This article mainly introduces the PHP Study Notes 7-JSON data operations. if you are interested in the PHP Tutorial, you can refer to it. JSON, the 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 standard, mainly used to exchange data with the server. Similar to XML, it is an independent language and has great advantages in cross-platform data transmission.
Create a json. php file and perform the encode operation first:
1 // encode2 // Generate JSON format data 3 $ arr = array (1, 2, 3, 4, 5, 6, 7, 8, 9, 'hello', 'php '); 4 echo json_encode ($ arr); // json_encode: converts an object to json format data.
The result is [1, 2, 3, 4, 5, 6, 7, 8, 9, "Hello", "PHP"].
Then perform the decode operation:
1 // decode decoding 2 $ jsonStr = '{"h": "Hello", "w": "World", "0": [3, 2, 1]}'; 3 $ obj = json_decode ($ jsonStr); 4 echo $ obj-> h; // you can obtain the result by using the member access method.
The above introduces the PHP Study Notes 7-JSON data operations, including the content, hope to be helpful to friends who are interested in PHP tutorials.