Home >Backend Development >PHP Tutorial >A brief discussion on JSON data operations in PHP, a brief discussion on phpjson data_PHP tutorial

A brief discussion on JSON data operations in PHP, a brief discussion on phpjson data_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:47:55832browse

A brief discussion on JSON data operations in PHP, a brief discussion on phpjson data

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 do the encode operation first:

 //encode
 //生成JSON格式数据
 $arr = array(1,2,3,4,5,6,7,8,9,'Hello','PHP');
 echo json_encode($arr);//json_encode:把一个对象转换成json格式数据

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

Do the decoding operation again:

 //decode 解码
 $jsonStr = '{"h":"Hello","w":"World","0":[3,2,1]}';
 $obj = json_decode($jsonStr);
 echo $obj->h;//使用成员访问的方式就可以得到结果

After you know the simple usage method, you can try to capture API data, such as weather...

The above is the entire content of this article, I hope you all like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1024925.htmlTechArticleA brief discussion of JSON data operations in PHP, a brief discussion of phpjson data JSON, the full name is JavaScript Object Notation. It is a light...
Statement:
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