Home > Article > Backend Development > How to convert json to string in php
In PHP, you can use the json_decode function to convert json to string. The function of this function is to decode the string in JSON format. Its usage syntax is "json_decode ( string $json [, bool $assoc.. .])".
Recommendation: "PHP Video Tutorial"
json_decode — Decode strings in JSON format
Description
json_decode ( string $json [, bool $assoc = FALSE [, int $depth = 512 [, int $options = 0 ]]] ) : mixed
Accepts a JSON encoded string and converts it into a PHP variable
Parameters
json
The json string to be decoded Format string.
This function can only handle UTF-8 encoded data.
Note:
PHP implements a superset of JSON, refer to » RFC 7159.
assoc
When this parameter is TRUE, it will be returned array instead of object.
depth
Specifies the recursion depth.
options
Mask consisting of JSON_BIGINT_AS_STRING, JSON_INVALID_UTF8_IGNORE, JSON_INVALID_UTF8_SUBSTITUTE, JSON_OBJECT_AS_ARRAY, JSON_THROW_ON_ERROR. The behavior of these constants is further described on the JSON constants page.
Return Value
Returns data encoded in json via the appropriate PHP type. The values true, false and null return TRUE, FALSE and NULL accordingly. If json cannot be decoded, or the encoded data depth exceeds the recursion limit, NULL will be returned.
The above is the detailed content of How to convert json to string in php. For more information, please follow other related articles on the PHP Chinese website!