In PHP, you can use the json_encode(string array, true) method to convert a string array into a json object. Note: The default return value of json_encode is not a JSON object, but a JSON format string; if you want to convert it into a json object, you need to add the parameter true at the end.
PHP json_encode() is used to JSON encode variables. This function returns JSON data if executed successfully, otherwise it returns FALSE.
Syntax
string json_encode ( $value [, $options = 0 ] )
Parameters
value: The value to encode. This function is only valid for UTF-8 encoded data.
options: Binary mask consisting of the following constants: JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT
##Example: Convert string array to json object
The above is the detailed content of How to convert string array to json object in php?. For more information, please follow other related articles on the PHP Chinese website!