· JSON is self-describing and easier to understand
* JSON uses JavaScript syntax to describe data objects, but JSON is still language and platform independent. JSON parsers and JSON libraries support many different programming languages.
Environment configuration
##has been built-in in php5.2.0 and above versions JSON extension.
JSON function
#Function
Description
json_encode
Pair variables Encode JSON
json_decode
Decode the string in JSON format and convert it into a PHP variable
json_last_error
Return the last error that occurred
##json_encode
json_encode() is used to JSON encode variables. This function returns JSON data if executed successfully, otherwise it returns FALSE.
Syntax
##json_encode ($value,[,options = 0 ] )
Parameter
##· 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· Due to json only accept UTF-8 encoded characters, so the parameters of json_encode() must be UTF-8 encoded, otherwise you will get empty characters or null. When Chinese uses GB2312 encoding, or foreign language uses ISO-8859-1 encoding, special attention should be paid to this point.
Example
The following example demonstrates How to convert PHP array to JSON format data:
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning