Home > Article > Backend Development > Detailed analysis of PHP json_decode function_PHP tutorial
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 data returned was "{'stauts':'1', 'message':'Recharge successful'}".
After receiving it, the program uses json_decode to convert the result into an array, but the conversion result 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.