请问,php如何打印出从服务器返回的原始json

WBOY
Release: 2016-06-13 10:51:22
Original
971 people have browsed it

请教,php怎么打印出从服务器返回的原始json?
我用一个php从服务器请求,服务器返回了标准格式的json,然后赋值到$a,我现在想把原始json数据打印出来,怎么办?
echo只显示一个Array,print,prinf是空,print_r是显示出了,但已经不是json格式的数据了。

------解决方案--------------------
显然$a存储的不是json字符串,而是经过json_encode()后的PHP的数组。
相应的,你可以echo json_decode($a);
------解决方案--------------------
echo json_encode($a);即可,$a明显是decode过的字符串……
------解决方案--------------------
你使用了新浪的SDK,而SDK的作用即在开发便捷。虽然/statuses/home timeline的返回格式是json,但还是经过了SDK内部处理。
PHP不能直接操作json字符串,因此这个SDK帮你预先把json转换为PHP的数组。
------解决方案--------------------

PHP code
$ch = curl_init();  $ch = curl_init($url) ;  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ;  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); $out = curl_exec($ch);  $out = trim($out); curl_close($ch); $out = json_decode($out, true); var_dump($out);<br><font color="#e78608">------解决方案--------------------</font><br>异步直接用ajax不就行了吗,对json支持很好
Copy after login
探讨

非常感谢你提供了一个另外的解决方法,但是我用的前端html+js的异步处理方式,所以非常好用但是用不上。学习了!引用:

PHP code

$ch = curl_init();
$ch = curl_init($url) ;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ;
curl_setopt($ch, CU……
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!