Understanding of objects and arrays in two JSON structures, json Arrays
Introduction to JSON
JSON (JavaScript Object Notation) is a lightweight data exchange format. It is based on a subset of ECMAScript. JSON uses a completely language-independent text format, but it also uses a habit similar to the C language family (including C, C ++, C #, Java, JavaScript, Perl, Python, and so on ). These features make JSON an ideal data exchange language. Easy to read and write, and easy to parse and generate by machines (generally used to increase the network transmission rate ).
Json is an extremely simple and easy-to-understand data format. The json rules are as follows:
1) Separate the parallel data with commas.
2) The ing is represented by a colon.
3) The set (array) of the parallel data is represented by square brackets.
4) The ing set (object) is represented by braces.
JSON has two types of structure arrays and objects: arrays represent the set of ordered data, and objects represent the set of unordered data.
Take the following example:
$arr = array(111,'aaa','bbb');$arr1 = array('a' => 'aaa','b' => 222);$arr2 = array('a' => 'aaa','other' => array('bbb',1111));echo json_encode($arr); //[111,"aaa","bbb"]echo json_encode($arr1); //{"a":"aaa","b":222}echo json_encode($arr2); //{"a":"aaa","other":["bbb",1111]}
As shown in the preceding figure, because javascript does not support correlated arrays, json_encode () only converts the indexed array (indexed array) to the array format, and converts the associative array (associative array) to the object format.
Json support for PHP:
Json_encode only supports UTF-8-encoded data;
Json_decode always reflects only one PHP Object. If the second parameter is set to true, an array is returned:
$json = '{"a":"aaa","other":["bbb",1111]}';print_r(json_decode($json));print_r(json_decode($json, true));
The above is an understanding of the JSON structure objects and arrays introduced by xiaobian. I hope it will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!