Home >Backend Development >PHP Tutorial >Detailed explanation of the usage of PHP json_decode function
This article mainly introduces the PHP json_decode function. Friends who need it can come and refer to it. I hope it will be helpful to everyone.
1. Introduction to the function
1. This function has four parameters. Generally, the first two are used during use. Please refer to the manual for specific parameters.
2. The first parameter is a string in json format, and the second parameter is a boolean value (false is converted into an object, true is converted into an array, and the default is false). If the conversion fails, null is returned.
2. Problems encountered
In the project, a web service written in java was called, and the returned data was "{'stauts':' 1','message':'Recharge successful'}".
After receiving it, the program uses json_decode to convert the result into an array, but the result of the conversion is null, which is too strange.
After reading the manual, I found the following instructions in the manual, and I understood it at once.
Change the returned result to '{"stauts":"1","message":"Recharge successful"}' and then convert it into the array and it will be OK.
The above is the detailed content of Detailed explanation of the usage of PHP json_decode function. For more information, please follow other related articles on the PHP Chinese website!