PHP study notes 7-JSON data operations

WBOY
Release: 2016-08-08 09:21:56
Original
856 people have browsed 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 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格式数据
Copy after login

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;//使用成员访问的方式就可以得到结果
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!