Understanding of JSON data structures

Source: Internet
Author: User

JSON is a lightweight, text-based data interchange format that can easily pass character information in a specific character format, with a detailed interpretation of JSON below.
Json:
Full name: "JavaScript Object Notation", a text-based, language-independent, lightweight data Interchange format, in my opinion JSON features are concise, useful, in all the languages I have access to, Can be used across platforms, and there is no character formatting problem in the usual sense. XML is also a data interchange format, but the XML tag is more, often making the tag more than the data that needs to be passed, which increases the burden of character transmission. Therefore, if we can use JSON, we are more inclined to use JSON. Below is a simple description of the JSON
JSON-specified format: 1) data in key-value pairs 2) data separated by commas 3) curly braces Save Object 4) square brackets Save array
Two structures of JSON: JSON can have two representations: the object and array object structures begin with "{" Curly braces, ending with "}" curly braces. The middle section consists of a "," to split the open key value pair (Key/value) code as follows: [HTML]View PlainCopy
    1. {
    2. Key1:value1,
    3. Key2:value2,
    4. ...
    5. }
Where: The keyword needs to be a string, and the value can be any other data, such as: string, numeric value, Boolean, object, or null. The array structure begins with "[" square brackets, "]" and the square brackets end. The middle part is divided by "," to divide the object. The code is represented as follows: [HTML]View PlainCopy
    1. [
    2. {
    3. Key1:value1,
    4. Key2:value2
    5. },
    6. {KEY3:VALUE3,
    7. Key4:value4
    8. }
    9. ]


This is quite vague, using the programming language analogy: The specific difference between the two structures is the value of different ways. The object is data that is included with {}, such as {"Key": "Key2", "2048"}. This can be understood as String key= "1024x768", String key2= "2048". When a value is required, the corresponding value is taken according to the corresponding key. For the array structure, it can be understood as ["value", "Key", "test"], the structure, the value and array, by index value. In general, when mixing applications, an object holds information about an object, and the array holds multiple objects.
JSON is actually used:
In general, the actual JSON used is a data structure consisting of arrays plus objects. Here's a simple to complex JSON example: for the simplest JSON. You can use the following data structures: [HTML]View PlainCopy
    1. {"Firstkey": "Citron"}
As I said above, this example is equivalent to: Firstkey=citron; [HTML]View PlainCopy
    1. {
    2. "Firstkey": "Citron",
    3. "Address": "Beijing",
    4. "Phonenum": "111"
    5. }
Just add curly braces, add a specific format, it becomes JSON, such data structure, with more easy to read, more uniform format, such as the above sake, one can see this is about a person's information. But what if a string of data that needs to be passed is a lot of personal information? This is how arrays and objects are mixed:
[HTML]View PlainCopy
    1. {
    2. "People": [
    3. {"FirstName": "Brett", "LastName": "McLaughlin", "email": "AAAA"},
    4. {"FirstName": "Jason", "LastName": "Hunter", "email": "BBBB"},
    5. {"FirstName": "Elliotte", "LastName": "Harold", "email": "CCCC"}
    6. ]
    7. }
Parsing of the above example: in an array named people, 3 sets of data are stored, each containing a person's surname, name, and email. The question comes again, people the word is too broad, if I want to classify it, according to the occupation classification, and then transfer how to do. Workaround: Pass an object that contains an array of occupations, each of which contains a different person object, each containing the person's information.
[HTML]View PlainCopy
  1. {
  2. "Programmers": [{
  3. "FirstName": "Brett",
  4. "LastName": "McLaughlin",
  5. "Email": "AAAA"
  6. }, {
  7. "FirstName": "Jason",
  8. "LastName": "Hunter",
  9. "Email": "BBBB"
  10. }, {
  11. "FirstName": "Elliotte",
  12. "LastName": "Harold",
  13. "Email": "CCCC"
  14. }],
  15. "Authors": [{
  16. "FirstName": "ISAAC",
  17. "LastName": "Asimov",
  18. "Genre": "Sciencefiction"
  19. }, {
  20. "FirstName": "Tad",
  21. "LastName": "Williams",
  22. "Genre": "Fantasy"
  23. }, {
  24. "FirstName": "Frank",
  25. "LastName": "Peretti",
  26. "Genre": "Christianfiction"
  27. }],
  28. "Musicians": [{
  29. "FirstName": "Eric",
  30. "LastName": "Clapton",
  31. "Instrument": "Guitar"
  32. }, {
  33. "FirstName": "Sergei",
  34. "LastName": "Rachmaninoff",
  35. "Instrument": "Piano"
  36. }]
  37. }

Understanding of JSON data structures

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.