There are times when you may be unsure what format to choose when transmiting data between a server and web application. Here are a few reasons why you might choose to use JSON rather than XML and a few why you might choose XML rather than JSON.
Background Information
What is JSON?
more click link
JavaScript Object Notation (JSON) is a lightweight text-based open standard designed for human-readable data interchange. It is derived from the JavaScript programming language for representing simple data structures and associative arrays, called objects. Despite its relationship to JavaScript, it is language-independent, with parsers available for most programming languages.
Further reading: http://en.wikipedia.org/wiki/Json
Further reading: http://en.wikipedia.org/wiki/Json
What is XML?
Extensible Markup Language (XML) is a set of rules for encoding documents in machine-readable form. XML’s design goals emphasize simplicity, generality, and usability over the Internet.
Further reading: http://en.wikipedia.org/wiki/XML
Further reading: http://en.wikipedia.org/wiki/XML
Reasons to choose JSON over XML
- JSON requires less tags than XML – XML items must be wrapped in open and close tags whereas JSON you just name the tag once
- Because JSON is transportation-independent, you can just bypass the XMLHttpRequest object for getting your data.
- JavaScript is not just data – you can also put methods and all sorts of goodies in JSON format.
- JSON is better at helping procedural decisions in your JavaScript based on objects and their values (or methods).
- You can get JSON data from anywhere, not just your own domain. There’s no more proxy server nonsense.
- Yahoo has a really good YUI2 JSON API.
- JSON is easier to read than XML – Obviously a personal preference
Reasons to choose XML over JSON
- Easy to take XML and apply XSLT to make XHTML.
- XML is supported by many more desktop applications than JSON.
- JSON can be put in the XML on the way back to the client – the benefit of both! It’s called XJAX (stands for X-domain JavaScript And XML).
- Simply, AJAX includes XML in it and not JSON.
Still can’t decide? Flip a coin or use a JSON/XML converter.
No comments:
Post a Comment