PHP get JSON json_decode return null workaround

Source: Internet
Author: User

In the use of Json_decode JSON format string decoding is empty, page blank Ah, the whole half-day check here to check there, ask colleagues are useless.

Bing search today, the problem solved, originally there is a BOM head output, prawn solution is as follows:

1), Json_decode ($json, Boolean): $json is a JSON-formatted character, the second parameter is true when the conversion is an array, and the default false indicates

Convert to an object.

2), Json_decode Required string comparison is strict:

(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
Solution One:
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:

<?php
$info = Json_decode (Trim ($info, Chr (239). chr (187). Chr (191)), true);

Method Two: Transcode the Chinese before converting to JSON

Reprint Address: http://www.cnblogs.com/anns/p/5974143.html

Reprint Address: https://segmentfault.com/q/1010000002991973

PHP get JSON json_decode return null workaround

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.