I didn't notice these two functions before, and someone in the group asked yesterday. Discover the following things.
Header ("content-type:text/html;charset=utf-8"= Array ('a '=1,'b'== 2= = == json_decode ($arr _1); Var_dump ($obj); Echo $obj->a;
Results:
String ' {"A": 1, "B": 2} ' (length=13) string ' "{\" a\ ": 1,\" B\ ": 2}" ' (length=19) string ' "{\" a\ ": 1,\" B\ ": 2}" ' (length=19) String ' {' A ': 1, ' B ': 2} ' (length=13) object (StdClass) [1] public ' a ' = = int 1 public ' b ' = = int 21
Using Json_encode () two or n times will escape the previously-turned JSON string.
Look at the API for Json_encode ()
String Json_encode ( mixed $value
[, int $options
= 0])
This says that the first argument is a mixed type, except that the rest of the resource can. The following parameters. Don't want to deviate from the theme.
Since the first call to Json_encode () is an array, the second time the Json_encode () method is called, the argument is a string.
With Json_decode ();
Mixed json_decode ( string $json
[, bool $assoc
= False [, int $depth
= [ +], in T $options
= 0]])
The API says that only JSON strings can be placed.
But when we json_decode the second time, the arguments passed in are actually an array. Returned to us with an object.
Two times Json_encode () and two times Json_decode ()