Home >Backend Development >PHP Tutorial >Solution to the problem of passing JSON string to background PHP processing, json string_PHP tutorial

Solution to the problem of passing JSON string to background PHP processing, json string_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:51:03757browse

Solution to the problem of transferring JSON string to background PHP for processing. json string

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1133017.htmlTechArticleSolution to the problem of JSON string being passed to the background PHP for processing. The json string is involved in project development due to Incoming batch record arrays, because there are many fields, it is impossible to use ordinary...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn