json_encode()
This function is mainly used to convert arrays and objects into json format.
Output results:
json only accepts utf-8 encoded characters, and the parameters of json_encode() must be utf-8 encoded.
$obj = new person("zhangsan",20,100);
$foo_json = json_encode($obj);
echo $foo_json;
Output results:
When the attributes in the class are private variables, they will not be output.
json_decode()
This function is used to convert json text into the corresponding PHP data structure.
Output results:
Normally, json_decode() always returns a PHP object.
Convert to array: