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 independent of language and has great advantages in cross-platform data transmission.
Create a new file json.php and do the encode operation first:
1//encode 2//生成JSON格式数据3$arr = array(1,2,3,4,5,6,7,8,9,'Hello','PHP'); 4echo json_encode($arr);//json_encode:把一个对象转换成json格式数据
The result is [1,2,3,4 ,5,6,7,8,9,"Hello","PHP"]
Do the decode operation again:
1//decode 解码2$jsonStr = '{"h":"Hello","w":"World","0":[3,2,1]}'; 3$obj = json_decode($jsonStr); 4echo$obj->h;//使用成员访问的方式就可以得到结果
The above introduces PHP study notes 7-JSON data operations, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.