Home > Article > Backend Development > A brief discussion on JSON data operations in PHP_PHP tutorial
Knowledge points of this article: 1. Introduction to JSON data format, 2. Encoding data into JSON format, 3. Decoding JSON data , and operate it, friends in need 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, which is mainly used to exchange data with the server. Similar to XML, it is language independent and has great advantages in cross-platform data transmission
Create a new file json.php and perform the encode operation first:
?
2 3 4
|
//encode //Generate JSON format data $arr = array(1,2,3,4,5,6,7,8,9,'Hello','PHP');
|
1
2
3
4 |
//decode decoding $jsonStr = '{"h":"Hello","w":"World","0":[3,2,1]}'; $obj = json_decode($jsonStr); echo $obj->h;//You can get the result using member access |