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.