Introduction to JSON
JSON (JavaScript Object Notation) is a lightweight data interchange format. It is based on a subset of ECMAScript. JSON takes a completely language-independent text format, but also uses a similar idiom to the C language family (c, C + +, C #, Java, JavaScript, Perl, Python, and so on). These features make JSON an ideal data exchange language. Easy to read and write, but also easy to machine parse and generate (typically used to improve network transfer rates).
JSON is an exceptionally easy-to-understand data format, and the rules for JSON are only as follows:
1) The data is separated by commas (",").
2) The map is represented by a colon (":").
3) a set (array) of side data is expressed in square brackets ("[]").
4) The Set of Mappings (objects) are represented by curly braces ("{}").
JSON has two types of structure arrays and objects: arrays represent collections of ordered data, and objects represent collections of unordered data.
Look at the following example:
$arr = Array (111, ' AAA ', ' BBB '); $arr 1 = Array (' a ' = = ' aaa ', ' b ' = ' + 222); $arr 2 = Array (' a ' = = ' aaa ', ' other ' = arr Ay (' BBB ', 1111)); Echo Json_encode ($arr); [111, "AAA", "BBB"]echo Json_encode ($arr 1); {"A": "AAA", "B": 222}echo Json_encode ($arr 2); {"A": "AAA", "Other": ["BBB", 1111]}
From the above: because JavaScript does not support associative arrays, json_encode () only converts an indexed array (indexed array) into an array format, and the associative array (associative array) to the object format.
Description of PHP support for JSON:
Json_encode only supports UTF-8 encoded data;
Json_decode always reflects only one PHP object, with the second parameter true to return an array:
The above is a small series to introduce you to the JSON two structure of the object and the understanding of the group, I hope that we have some help, if you have any questions please give me a message, small series will promptly reply to you. Thank you very much for the support of the Scripting House website!