PHP output Chinese JSON string

Source: Internet
Author: User
Tags json php and urlencode

PHP and JavaScript are actually handy, and PHP native also provides support for the JSON format. Mainly includes JSON encoding and decoding two functions:

Json_endoce:http://cn.php.net/json_encode

json_dedoce:http://cn.php.net/json_decodejson_encode-the variable in JSON and returns the JSON form of the value, for example:

$arr = Array (' A ' =>1, ' B ' =>2, ' C ' =>3, ' d ' =>4, ' e ' =>5);

echo Json_encode ($arr);

?>

The above code executes after the output:

{"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}

If you want to encode a data source (typically an array), the value contains Chinese, and the output is Unicode encoding after json_encode processing.

$arr = Array (' A ' => ' Mango Station ');

echo Json_encode ($arr);

?>

The above code executes after the output:

{"A": "U8292u679cu5c0fu7ad9"}

The PHP bottom has done Unicode processing, if it is not intuitive enough, you can use the UrlEncode and UrlDecode methods to bypass the transcoding for Unicode process:

$arr = Array (' A ' =>urlencode (' Mango Station '));

Echo UrlDecode (Json_encode ($arr)); Output after execution of the above code:

{"A": "Mango Station"}

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.