When making the site CMS module, the Content field of the module contents is stored in JSON format, so the Json_decode () function is needed in the background for the editing of the module content (removing the saved data).
But at the time of parsing, the result of parsing with the Json_decode () function is always NULL and there is no array to parse. Here are the questions and analysis:
1. When outputting a JSON string, the code and page are displayed in the following:
Echo $content $res [0] [' Con '] [' content '];
Just consider $content, $res [0][' con '] [' content '] is the value of the content retrieved from the returned data, which is not to be considered here. This page displays:
{"Bpic": "Group1\/m00\/00\/0d\/rbak31sttzeae056aakwubmsagc339.jpg", "bname": "About1", "Breason": "3334" , "About2": "444", "ABOUT3": "555", "Tpic1": "Group1\/m00\/00\/0d\/rbak31stsygarpwhaamcd98u8xo736.jpg", "Tpic2": " Group1\/m00\/00\/0d\/rbak31sttzeaeneaaanwlboxmya393.jpg "," tpic3 ":" group1\/m00\/00\/0d\/ Rbak31sttsqarrumaakwubmsagc150.jpg "}
To beautify a little bit:
{
"Bpic": "Group1\/m00\/00\/0d\/rbak31sttzeae056aakwubmsagc339.jpg", "bname": "Breason", "ABOUT1": "3334", "About2": "444", "ABOUT3": "555", "Tpic1": "Group1\/m00\/00\/0d\/rbak31stsygarpwhaamcd98u8xo736.jpg", "Tpic2": " Group1\/m00\/00\/0d\/rbak31sttzeaeneaaanwlboxmya393.jpg "," tpic3 ":" group1\/m00\/00\/0d\/ Rbak31sttsqarrumaakwubmsagc150.jpg "}
2. Use Json_decode () to resolve the $content and print using Var_dump:
$content = Json_decode ($content,true);
However, the page shows NULL. At this point, use the Json_last_error () function to print the error, the page displays 4, which is a syntax error.
Echo $errorinfo = Json_last_error (); //Output 4 syntax error
Workaround:
This problem occurs because the double quotes are escaped in the JSON string, and only the Htmlspecialchars_decode () function is used to handle the $content:
$content = Htmlspecialchars_decode ($content);
At this point, using the Json_decode () function parsing, there is no problem, page output:
Array
[bname] =3334= 555
[Tpic2] = group1/m00/00/0d/rbak31sttzeaeneaaanwlboxmya393.
)
PHP Json_decode function Parsing JSON result NULL resolution method