This function accepts four arguments as listed below. This is the reverse operation of JSON encode, obviously used to convert JSON encoded data into its original PHP data type from where it is encoded initially.įor that, the second method json_decode() we have listed at the beginning of this article, will be used. While using JSON_FORCE_OBJECT on encoding PHP array value, then each array element will be added to an index even if the input array doesn’t have an index.PHP json_encode() is used to convert any type of data except PHP resource data.Print "JSON Formatted String with white space:". $strJsonFormat_with_space = json_encode($input_array, JSON_PRETTY_PRINT) So, the following program handles a few json_encode() functions invoked with some of the available JSON encode constants as its options parameter. Now, it’s time to see an example PHP program to perform JSON encoding. JSON_UNESCAPED_UNICODE – It prevents from escaping Unicode characters.JSON_UNESCAPED_SLASHES – It prevents escaping slashes (/).JSON_PRETTY_PRINT – pretty print is used for adding white space with the JSON formatted data.JSON_BIGINT_AS_STRING – This constant is used to convert the log integer value as a string.JSON_NUMERIC_CHECK – PHP JSON encode function will return numbers as a result of encoding given a number with the string data type.JSON_FORCE_OBJECT – Using this, json_encode will return an object for given input data except for the associative array.JSON_HEX_QUOT – converts double quotes (“) into \u0022.JSON_HEX_APOS – encode apostrophe (‘) with \u0027.JSON_HEX_AMP – Used to encode data by replacing ampersand symbol (
0 Comments
Leave a Reply. |