Introduction to JSON and XML

Source: Internet
Author: User
Both JSON and XML can be used as data definitions. Both of them are affirmed in asynchronous transmission, and the difference between them should be mainly due to the simplicity of resolution.
JSON defines data in the following ways: {} and []. {} represents objects, [] represents arrays, and XML represents information through <> layers. Let's take a look at these two different methods.
As we all know, in the object-oriented three-layer architecture, we usually abstract the real object into an object and value its attributes. For example, a person has his/her own name, gender, age, work, and sports information. In JSON format:

VaR Person = {
" Name " : " Name " ,
" Sex " : " Sex " ,
" Age " : " Age " ,
" Work " :[
{ " 1986-1989 " : " Firstwork " , " 1989-1999 " : " Secondwork " , " 1999-2007 " : " Thirdwork " } ,
" Otherthings "
]
}

In XML format:

< Person >
< Name > Name </ Name >
< Sex > Sex </ Sex >
< Age > Age </ Age >
< Work >
< Firstwork >
< Time > 1986-1989 </ Time >
< Workname > Firstwork </ Workname >
</ Firstwork >
< Secondwork >
< Time > 1989-1999 </ Time >
< Workname > Secondwork </ Workname >
</ Secondwork >
< Thirdwork >
< Time > 1999-2007 </ Time >
< Workname > Thirdwork </ Workname >
</ Thirdwork >
< Otherthings > </ Otherthings >
</ Work >
</ Person >

Of course, we can't just define the data. The ultimate goal is to present the data to the user or extract it for use. JSON-defined data can be accessed directly through javascript. After all, it is directly a JavaScript Object. For example, you can use person. Name to access data. Data defined in XML can be parsed using Dom.

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.