The contents of the array are returned with a null value using the Json_encode return character content

Source: Internet
Author: User

If you use the Json_encode array to turn to a JSON string, you find that all of the characters are empty, so that the point is that your page is not UTF8 encoded, in the PHP manual for Json_ The value to be encoded in encode has indicated that the encoding of all strings must be UTF-8;

So if your page is not UTF-8 encoded, you need to transcode the contents of your array, specifically how to transcode? Below, for example, your page is encoded using GBK:

function Gbk2utf8 ($data) {if (Is_array ($data)) {foreach ($data as $key = $value) {$data [$key]=call_user_func (__ FUNCTION__, $value);} return $data;} Return Iconv ("GBK", "Utf-8", $data);}

The contents of the array are returned with a null value using the Json_encode return character content

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.