PHP returns JSON exception

Source: Internet
Author: User
json_encode($rst)An unknown character appears before the JSON returned by the function ���{"status":"ok"}
Causes parsing to fail and how to handle it?

Reply content:

json_encode($rst)An unknown character appears before the JSON returned by the function���{"status":"ok"}
Causes parsing to fail and how to handle it?

Because the problem is not necessarily the current PHP document, may be a previous document accumulated, inconvenient to troubleshoot, so you can use before output to ob_clean(); clear the previous output cache.

Supplement: Can be through "Grep-rli $ ' \xef\xbb\xbf '." Globally finds files with BOM encoding.

The PHP file is encoded

Set the file encoding

PHP's JSON processing function only supports UTF8 encoding for Chinese characters.

Change the file encoding format of the output JSON to UTF8 no BOM

  • Related Article

    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.