: This article describes how to use json_encode and json_decode to transmit data containing special characters in php. For more information about PHP tutorials, see.
Json_decode
Mixed json_decode (string $ json [, bool $ assoc = false [, int $ depth = 512 [, int $ options = 0])
Accept a JSON string and convert it to a PHP variable
Json_encode
String json_encode (mixed $ value [, int $ options = 0])
Return the JSON format of the value.
For example, interface_x needs to obtain the data transmitted in interface_y, and data contains special characters, so that these special characters can be stored in the array in interface_y, and then json_encode is converted into json
Format string, passed to interface_x, json_decode in interface_x.
$json2 = json_decode($json, true);//echo "json2:";//var_dump($json2);
Interface_y processes strings containing special characters, stores them into arrays, and performs json_encode:
$value = '~!@#$%^&*()_+-={}:";<>?/\123456789123';$data = array("key" => $value);$json = json_encode($data);//echo "json:" . "\n";//var_dump($json);
In interface_x, json_decode is used to convert the input json data into an array.
Refer:
Http://php.net/manual/zh/function.json-decode.php
Http://php.net/manual/zh/function.json-encode.php
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above section describes how to use json_encode and json_decode to pass data containing special characters in php, including some content, and hope to help friends who are interested in PHP tutorials.