Home > Backend Development > PHP Tutorial > php 开发api 再输出json数据时 是echo 还是print_r,该怎么解决

php 开发api 再输出json数据时 是echo 还是print_r,该怎么解决

WBOY
Release: 2016-06-13 13:32:25
Original
947 people have browsed it

php 开发api 再输出json数据时 是echo 还是print_r
假设 $selectRows是个数组 再输出时(也就是外部调用时)是echo 还是 return 还是print_r之类的 为啥外部一直获取不到我是 echo urlencode(json_encode($selectRows)),外部在调用时$gc=file_get_contents(http://域名/类名/方法名/传入的值) 但是在输出时,直接输出$gc还可以接收到数据 但是 print_r(urldecode(json_decode($selectRows)))打印数组时 却什么也没有了

------解决方案--------------------
$selectRows是你的数组 这样输出 : echo urlencode(json_encode($selectRows));
用file_get_contents得到$gc后,echo json_decode(urldecode($gc));
准没错

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