JSON vs XML

Source: Internet
Author: User
Ajax (asynchronous javas BytesAnd XML) in the end, it is a technology in which the browser asynchronously reads XML content from the server. The current technology is related to XML, and the concept is used as a joke, just like a gold outfit. The people outside the door were very busy, but the people inside the door shook their heads. What about XML? In fact, xml = TXT. XML is just a text that conforms to many specifications. It is nothing, but a file that saves characters. The browser asynchronously reads only the text content on the server, so you do not have to stick to XML during Ajax development. [Copyright, www.jialing.net]

  The origin of JSON

XML is used to format data. Is there any better way if we don't need XML? The answer is JSON. Before introducing JSON, let me first introduce javasThis script language. The scripting language has its own talent for dynamic execution. That is, we can put the statement we want to execute in the string, through EVThe dynamic execution function al_r () is used for execution. The content in the string will be executed like the script we wrote.

Example 1:

<HTML>
<Head>
<Title> EVAl Example 1 </title>
</Head>
<Body>
<SCRIPT>
STR = "alert ('hello ')";
EVAl_r (STR );
</SCRIPT>
</Body>
</Html>
The Hello window is displayed.

We can put any script statement in the string, including the declaration statement:

<HTML>
<Head>
<Title> EVAl Example 2 </title>
</Head>
<Body>
<SCRIPT>
Define = "{Name: 'Michael ', email: '17bity @ gmail.com '}";
EVAl_r ("daTa = "+ define );
Alert ("name:" + DATa. Name );
Alert ("Email:" + DATa. Email );
</SCRIPT>
</Body>
</Html>
If the asynchronous text in the background is javasThe statement of declare, so it is not an EVCan the Al method be parsed? How efficient is this process for parsing complex XML!

Now let's tell you what JSON is: javasJsonobject notation. I prefer to translate it into javasStatement object declaration. For example, to load some address book information from the background, if it is written as XML, as follows:

<Contact>
<Friend>
<Name> Michael </Name>
<Email> 17bity@gmail.com </Email>
<Homepage> http://www.jialing.net </Friend>
<Friend>
<Name> JOHN </Name>
<Email> john@gmail.com </Email>
<Homepage> http://www.john.com </Friend>
<Friend>
<Name> Peggy </Name>
<Email> peggy@gmail.com </Email>
<Homepage> http://www.peggy.com </Friend>
</Contact>
In JSON format:

[
{
Name: "Michael ",
Email: 17bity@gmail.com ",
Homepage: "http://www.jialing.net"
},
{
Name: "John ",
Email: john@gmail.com ",
Homepage: "http://www.jobn.com"
},
{
Name: "Peggy ",
Email: peggy@gmail.com ",
Homepage: "http://www.peggy.com"
}
]

The simplest is not just expression, but the most important thing is to discard the confusing Dom parsing. BecauseThe statement specification of the statement, the statement Crip will automatically help you resolve. The basic method to use JSON in Ajax is to load the background declaration javas on the foreground.The string of the sequence object, using EVTo convert it to the actual object, and then update the page information through DHTML.

JSON format

The basic JSON format is as follows:

? An object is a set of attributes and value pairs. An object starts with "{" and ends "}". Each attribute name and value is separated by a ":" prompt, and.

? An array is a set of ordered values. An array starts with "[", ends with "]", and values are separated. ? The value can be a string, number, true, false, or null in quotation marks, or an object or array. These structures can be nested. ? The definition of a string is basically the same as that of C or Java .? The definition of numbers is also basically the same as that of C or Java.
JSON XML

? Readability

The readability of JSON and XML is comparable. One side is the suggested syntax and the other side is the standard tag format, which makes it difficult to distinguish between the two.

? Scalability

XML is inherently highly scalable, and JSON is also available. There is nothing XML can be extended, and JSON cannot.

? Encoding difficulty

XML has rich coding tools, such as dom4j and JDOM, and JSON also provides tools provided by json.org. However, JSON encoding is much easier than XML, JSON code can be written without tools, but it is not easy to write XML.

? Decoding difficulty

XML parsing takes into account the parent node of the child node, which is confusing, and the difficulty of JSON Parsing is almost 0. There is nothing to say about XML.

? Popularity

XML has been widely used in the industry, and JSON is just the beginning. However, in the specific field of Ajax, the future development of XML must be in JSON. Then Ajax should become ajaj (asynchronous javasBytesAnd JSON.
# JavasExamples/ajax Columns

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.