PHP Json_decode return null parse failure reason

Source: Internet
Author: User

Before PHP5.4 the Json_decode function had two parameters Json_decode had two parameters, the first is the string to parse, the second is whether to parse to array

Json_decode requires a strict string comparison:
(1) Using UTF-8 encoding
(2) cannot have a comma at the last element
(3) cannot use single quotation marks
(4) cannot have r,t, if please replace

So here's the problem. Returns the invisible character of the BOM header in the returned JSON string, some editors default to the BOM header, and the following processing is required to correctly parse the JSON data:

$result = Json_decode (trim($contents,chr(239).  CHR(187). CHR (191)),true); Print_r ($result);

Reference: http://www.jishutie.net/p/19227.html

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.