PHP json 类型

WBOY
Release: 2016-06-23 13:42:35
Original
1072 people have browsed it

有时候需要用json的格式返回数据,json是一个很常用的数据传输方式。下面是一个最简单的例子。就是说只需要设置一下文档类型是 json 的就可以了。

<?phpheader ('Content-Type: application/json; charset=UTF-8');$s = array('1'=>'hello world','2'=>'linux world');$show = json_encode($s);echo $show;?>
Copy after login

用浏览器访问的效果就会像上面这样子。当然,需要浏览器安装jsonviewr插件。由于chrome 商店老是上不了,所以能不能装上这个插件还需要看脸。如果碰巧上去了,那就好办了,在商店里搜jsonview就可以了。不好意思,我又上去了。


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