XML has become the defacto standard for data transmission. In Ajax-based applications, XML can be accessed by the XMLHttpRequest object in XML format using the responseXML property or in string format using the responseText property.
However, choosing XML as a data exchange format has its downsides, too. It is not suited especially when heavy data has to be exchanged between the server and client. Why? First, it becomes difficult to parse huge XML and access data; second, the XML data format is higher in bytes in what could have been accomplished in a smaller form.
Douglas Crockford has created an alternate format, which is extremely lightweight and string-based for data exchange between server and client. Called JSON, it is an acronym for JavaScript Object Notation—a light-weight data interchange format.
JSON supports two data structures: objects and arrays. Objects are unordered collections of name/value pairs. This object is enclosed in { and }. Name and value are separated by :, and the name/value pairs are separated by ,. Arrays are an ordered sequence of values. An array is enclosed in [ and ], and its values are separated by ,.
The name is a string enclosed in double quotes. Values can be any one of the following data types: String, Number, Boolean [true or false], Object, Array, and null.
JSON is flexible in the sense that it can represent any data structure as is, and it provides the flexibility to add any new field to an existing structure without making the existing programs obsolete. The big advantage of JSON is that it’s more compact and a lot easier to parse than XML. All we need to do is to pass the JSON string to the eval of JavaScript. The eval function of JavaScript evaluates the input string and assigns the output to the HTML elements. It should be noted, however, that usage of the eval function hampers performance. You might have to think of a different option, but only when the data is huge—converting huge strings on the client side might cause delays to the end user. But the best part of JSON is that you can have this parsing in a .js file and can include it in any page. Also, JSON has no version number because the specification is declared stable forever. There are several JSON parsers that support most of the programming languages; these parsers can be downloaded from www.json.org/.
Most of the ASP.NET Ajax server controls use JSON as a data interchange format. The server controls emit JSON strings, and the Microsoft Ajax Client Library parses this data using the internal .js files and hands the data to the client. This format is preferred because of its size, compactness, and ease of parsing the data. Overall, it helps improve the performance of the ASP.NET Ajax application.
JSON Introducing in ASP.Net
Hot on Web: