PHP removes the backslash \ and the backslash _php instance in the JSON string before removing the double quotes

Source: Internet
Author: User

The JSON string that is uploaded to Php via Ajax is sometimes added with a backslash "\" to escape, and the PHP process needs to remove the backslash first and then Json_decode.

$str = stripslashes ($_post[' json ')); 

Ps:php get crawl JSON how to remove the backslash before double quotes

You are not the standard JSON format data, you can first replace \ "" can be.

Then use the Json_decode () system function to convert it to a JSON object, if you want to convert to an array plus the second argument to true.

If the output is still null due to the existence of BOM header information,

Copy Code code as follows:

$arr = Json_decode (Trim ($json, Chr (239). chr (187). Chr (191)), true);

Conversion can be.

This article is complete, and I would like to help you in using PHP to remove the backslash in the JSON string and to remove the backslash before the double quotes.

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.