How can I let Json_decode parse a string with a slash

Source: Internet
Author: User

such as the front desk a JS object:
{
AA: "Cc\dd"
}
$d = ' {\ ' aa\ ": \" cc\\dd\ "} ';
This time with Json_decode ($d, true) will return NULL, if handled with Stripslashes, the slash is gone, will become AA:CCDD
How to support the decode.
Thank you.

------Answer---------

------Other answers (100 points)---------


"\ \" is parsed as "\" when it is output in the browser.
Proposed landlord in front of the "AA": "CC\DD" changed to "AA": "Cc\\dd"
This is accepted as ' {\ ' aa\ ': \ ' cc\\\\dd\ '} '
Then you might want to use a JSON class. The next code is too long to be posted.

PHP Code
<?php include (' json.class.php '), $json _str = ' {\ ' aa\ ': \ ' cc\\\\dd\ '} '; $json = new My_json (); $json _str = Stripslashes ( $json _str); Var_dump ($json->decode ($json _str));//array ' aa ' = = String ' Cc\dd ' (length=5)?>


Or the landlord can choose to pass the link encodeURI () to encode
or encode the content encodeuricomponent ()

How can I let Json_decode parse a string with a slash

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.