JSON is currently one of the most popular data interchange formats, it is necessary to be very familiar with its various aspects of knowledge, this time let’s take a look at its format types.

Data exchange format

  • Basic types of
  • An array type
  • Nested object

A case in field

Basic types of

{” key “: value,” key “:” value “,… }, the name of the key followed by a colon, followed by the corresponding value, if there are other key-value pairs separated by commas.

{
    "name": "Zhang"."age": 18."sex": true
}
Copy the code

An array type

[{” key “: value,” key “: value},{” key” : value, “key” : “value “},…] , with the data separated by commas.

[{"name": "Zhang"."age": 18."sex": true
    },
    {
        "name": "Bill"."age": 19."sex": false}]Copy the code

Nested object

From the above two types, a variety of nested types can evolve because of the immobility of the values.

{
    "name": "teacher"."computer": {
    "CPU":"intel7, "disk":"512G"},"students": [{"name":"Zhang SAN","age": 18,"sex": true }, { "name":"Li si","age: 19, ""sex": false } ] }Copy the code

More details and the formatting to note can be found directly on the JSON website.

Extension to XML

XML is also a data interchange format. It’s not a language, it’s a data interchange format across languages. JSON is slowly taking its place, but we still see it all over the place, so it’s a must-learn, and we’ll take a look at its syntax formatting rules.

All XML elements must have a close tag

In HTML, it is common to see elements without closing tags:

<p>This is a paragraph
<p>This is another paragraph
Copy the code

In XML, it is illegal to omit the closing tag. All elements must have a close tag:

<p>This is a paragraph</p>
<p>This is another paragraph</p>  
Copy the code

** Note: ** You may have noticed that XML declarations do not have closing tags. This is not a mistake. Declarations are not part of the XML itself. It is not an XML element and does not require a closing tag.

XML tags are case-sensitive

XML elements are defined using XML tags.

XML tags are case-sensitive. In XML, tags are different from tags.

Open and close tags must be written in the same case:

<Message>This is wrong.</message>

<message>This is correct.</message> 
Copy the code

** Open and close tabs are often referred to as opening and closing tabs. Whichever term you prefer, the concept is the same.

XML must be properly nested

In HTML, it is common to see elements that are not properly nested:

<b><i>This text is bold and italic</b></i>
Copy the code

In XML, all elements must be properly nested with each other:

<b><i>This text is bold and italic</i></b>
Copy the code

In the above example, proper nesting means that since the element is opened within the element, it must be closed within the element.

XML documents must have a root element

An XML document must have one element that is the parent of all other elements. This element is called the root element.

<root>
  <child>
    <subchild>.</subchild>
  </child>
</root>
Copy the code

XML attribute values must be quoted

Like HTML, XML can have attributes (name/value pairs).

In XML, attribute values of XML are quoted. Examine the two XML documents below. The first is false and the second is true:

<note date=08/08/2008>
	<to>George</to>
	<from>John</from>
</note> 
<note date="08/08/2008">
	<to>George</to>
	<from>John</from>
</note> 
Copy the code

The error in the first document is that the date attribute in the note element is not quoted.