Home  >  Article  >  Backend Development  >  Detailed explanation of the usage of PHP json_decode function

Detailed explanation of the usage of PHP json_decode function

巴扎黑
巴扎黑Original
2017-05-26 15:32:002776browse

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!

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