JSON two structure object and array understanding _php instances

Source: Internet
Author: User
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!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.