Home > Backend Development > PHP Tutorial > PHP study notes 7-JSON data operation, php study notes 7-json_PHP tutorial

PHP study notes 7-JSON data operation, php study notes 7-json_PHP tutorial

WBOY
Release: 2016-07-13 09:48:21
Original
937 people have browsed it

PHP study notes 7-JSON data operations, php study notes 7-json

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:

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

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

Do the decoding operation again:

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

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1023839.htmlTechArticlePHP study notes 7-JSON data operations, php study notes 7-json JSON, the full name is JavaScript Object Notation. It is based on the JavaScript programming language ECMA-262 3rd Edition-December 1999 standard...
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template