XML or JSON? It’s a question

I used XML much earlier than JSON since I usually use Asp.net to develop webiste or B/S based management system, it’s more easily to use XML than using Json in asp.net, and after I started to use jQuery for the front-end page, I found that JSON was really a niect data format, so now I have gradually shifted the focus of data format to the JSON.

Let’s see the respective advantages and disadvantages of XML and JSON.

XML’s advantages
1. Uniform format, consistent with standard
2. Can be described by the complexity of the structure
3. Easy to interact with other systems, data sharing is more convenient

XML’s disadvantages
1. Data size is bigger than JSON, the format is complex, transmission needs more bandwidth.
2. Both front-end and server side need to use a lot of code to resolve XML.
3. Different web broswers have different ways to handle XML, developers need to write several versions code for every browser, which driver them crazy.

JSON’s advantages
1. Has simple data format, smaller size which saving bandwidth.
2. Easy to handle, the client JavaScript can simply read a JSON data through Eval ().
3. jQuery providers a common solution to read / write JSON data, developers needn’t to care which broswer are used any more.

JSON’s disadvantages
1. For some complex data, JSON is a bit inadequate.
2. compared with XML, JSON has a smaller readability

Let’s look at their differences with a simple example.

XML:
<?xml version=”1.0″ encoding=”utf-8″ ?>
<world>
<continent>
<name>North America</name>
<countries>
<country>
<name>USA</name>
<capital>Washington</capital>
</country>
<country>
<name>Canada</name>
<capital>Ottawa</capital>
</country>
</countries>
</continent>
<continent>
<name>Oceania</name>
<countries>
<country>
<name>Australia</name>
<capital>Canberra</capital>
</country>
<country>
<name>New Zealand</name>
<capital>Wellington</capital>
</country>
</countries>
</continent>
</world>

JSON:
{
“world”: {
“continent”: [
{
“name”: “North America”,
“countries”: {
“country”: [
{
“name”: “USA”,
“capital”: “Washington”
},
{
“name”: “Canada”,
“capital”: “Ottawa”
}
]
}
},
{
“name”: “Oceania”,
“countries”: {
“country”: [
{
“name”: “Australia”,
“capital”: “Canberra”
},
{
“name”: “New Zealand”,
“capital”: “Wellington”
}
]
}
}
]
}
}

It’s clear that JSON has the smaller size but XML has the better readability.

So, Proposed selection principle of mine:

1. For complex data structures, using XML and for a simple data structure, using JSON.

2. I recommend JSON in the Internet data transmission

3. For the difference between the front-end and server side, you can use XML in the server side and use of JSON in the front-end, the conversion will be completed in the server.

Notice: All articles are original by ComputerBlog.com.au, please make sure the original URL will be kept in reproduction.

Post Footer automatically generated by wp-posturl plugin for wordpress.

(2)

Share This:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.