php method to convert json into an array: first create a php sample file; then create a set of json format data; then convert json into an array through the "json_decode" function; finally print the conversion result through "var_dump" That’s it.
php converts json into an array:
As shown below:
//json格式数据 $data = '[{ "F_ModuleId": "1", "F_ParentId": "0", "F_EnCode": "SysManage",}]'; //转换成数组 $arr = json_decode($data,true); //输出 var_dump($arr);
Recommended: "PHP Tutorial"
Related introduction:
json_decode — Decode a string 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
To be decoded A string in json string format.
This function can only handle UTF-8 encoded data.
Note:
PHP implements a superset of JSON as specified in the original » RFC 7159.
assoc
When this parameter is TRUE, array will be returned 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 into array in php. For more information, please follow other related articles on the PHP Chinese website!