AJAX & JSON Serialization
This article provides an overview of JSON's rules and illustrates how it is used in AJAX-enabled web applications.
It differs from XML in three important ways:
· It is much simpler to understand and implement than XML;
· It is less verbose, resulting in a slimmer payload; and,
JSON - In AJAX-enabled Web Applications
When using Script Services (Web Services) in an AJAX-enabled ASP.NET application, the ASP.NET AJAX framework automatically handles generating and parsing the JSON messages sent between the client and server.
In such a case, you can serialize the additional input parameters using JSON.
The Microsoft ASP.NET AJAX Framework includes both client- and server-side mechanisms for creating and parsing JSON messages.
Below is a simple Server Side JSON example.
List<int> selectedCategories = new List<int>();
* To serialize an object, use the Serialize method. To deserialize a JSON string, use the Deserialize<(Of <(T>)>) or DeserializeObject methods.
JSON Message Format - Syntax
Here's the one-line overview:
“JSON-formatted messages are composed of a single, top-level object or array, which itself can hold objects, arrays, strings, numbers, Boolean values, or the value null. “
* Name/value pairs are encased in curly braces,
var emp = eval( jsonString );
alert("Employee " + emp.Name + " makes " + emp.Salary + " per year!");