Home >Backend Development >PHP Tutorial >Solution to the problem of passing JSON string to background PHP processing, json string_PHP tutorial
During project development, due to the input of batch record arrays, due to the large number of fields, So it is impossible to transmit it in the ordinary way &a=322&=gsd&v=rwe, so I thought of passing the JSON format to the front end content=[{'a':2321,'b':'gsd','c':' dww'},{'a':'4sd','b':'gsd2','c':'dww3'},...] , in this case it is also very convenient to parse multiple records in the background, but I When passing it like this, what the background receives is the format [{'a':2321,'b':'gsd','c':'dww'}...], and what I need is the standard JSON format. Strings are parsed using PHP's json_decode and directly converted into arrays. This makes it easier for me to operate. I searched online and many students encountered the same problem as me. After searching for a long time, I still couldn't find the answer. In the end, I decided to solve it myself. It’s out, stripslashes. Use this function in PHP to convert the obtained JSON string and it’s OK.
In fact, this problem is caused by the get_magic_quotes_gpc() function. If the configuration in php.ini is off, this problem should not exist, so when using this function, add judgment
//$json 为接收的JSON字符串 if(get_magic_quotes_gpc()==1){ $json = stripslashes($json); }
To be superfluous, I haven’t finished PHP in two years and have forgotten all about it. Recently, I have to read the manual again for project needs