Example of JSON data generated by php

Source: Internet
Author: User

Theme after a long time

The result shows that there is a problem with the local build.

Why don't we bother? (? ^ ?)?

When posting in Baidu POST Bar

JSON is often used to obtain some values.

So how does PHP output JSON data?

In fact, the 'json _ encoding' function already exists in PHP.

The code is as follows: Copy code
<? Php
$ Array = array (
'Newest _ Ver '=> 'None ',
'Api _ list' => 'http: // www.111cn.net /',
'Announcement '=> 'None'
);
$ Result = json_encode ($ array );
Echo $ result;
?>

If you directly use json_encode to convert the Chinese character to NULL, this problem does not exist after urlencode.

Json data is garbled

Only UTF-8 can be used to generate a json string. However, you can use the following function to implement utf8 array transcoding and then directly use json_encode ():

The code is as follows: Copy code

Function output ($ arr = array () {return eval ('Return '. iconv ('gb2312', 'utf-8', var_export ($ arr, true )). ';');}

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.