How does php print the original json returned from the server?

Source: Internet
Author: User
Tags php print
How does php print the original json returned from the server? I used a php request from the server. the server returned the json in the standard format and assigned a value to $ a. What should I do if I want to print the original json data? Echo only displays one Array, print, prinf is empty, and print_r is displayed, but it is not j's advice. how does php print the original json returned from the server?
I used a php request from the server. the server returned the json in the standard format and assigned a value to $ a. What should I do if I want to print the original json data?
Echo only displays one Array, print, prinf is empty, and print_r is displayed, but it is no longer in json format.

------ Solution --------------------
Obviously, $ a is not a json string, but an array of PHP after json_encode.
Correspondingly, you can echo json_decode ($ );
------ Solution --------------------
Echo json_encode ($ a); you can, $ a is obviously a decode string ......
------ Solution --------------------
You have used the Sina SDK, and the function of the SDK is convenient for development. Although the returned format of/statuses/home timeline is json, it is still processed by the SDK.
PHP cannot directly manipulate json strings. Therefore, this SDK helps you convert json into PHP arrays in advance.
------ Solution --------------------
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 );
------ Solution --------------------
Is it okay to use ajax asynchronously and directly? it supports json well. Discussion

Thank you very much for providing another solution, but I use the frontend html + js asynchronous processing method, so it is very useful but not usable. Learning! Reference:

PHP code

$ Ch = curl_init ();
$ Ch = curl_init ($ url );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
Curl_setopt ($ ch, CU ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.