Home>

The json string passed to php via ajax is sometimes escaped with a backslash "\". PHP needs to remove the backslash first when processingThen json_decode.

$str=stripslashes ($_ post ["json"]);
$arr=json_decode ($str, true);

ps:how to get json in PHP to remove backslashes in front of double quotes

You don't count the standard json format data,You can replace \ "with" first.

Then use the json_decode () system function to convert it to a json object. If you need to convert to an array, add the second parameter to true.

If the output is still null, it is due to the presence of the bom header information.

$arr=json_decode (trim ($json, chr (239) .chr (187) .chr (191)), true);

Just convert.

php
  • Previous "Unknown collation:‘ utf8mb4_unicode_ci "error appears in the WordPress import database
  • Next Explain the use of basic class libraries and language packs in Java