This article provides an overview of JSON's rules and illustrates how it is used in AJAX-enabled web applications.
Transmitting information over the Internet requires the sender to serialize it into some string-based format prior to sending it, and the receiver to deserialize it back into an object state that it can work with. For instance, if the client wants to send an array of integers to the server it must convert that array from its in-memory representation into a string, so that it can be transmitted across the network. Likewise, upon receiving the request, the receiver must turn that string representation of an array of integers back into an array of integers, so that it can use it programmatically.
XML was designed to serialize complex data into a string-based format, and early
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,
This article provides an overview of JSON's rules and illustrates how it is used in AJAX-enabled web applications. We'll also look at using the Microsoft ASP.NET AJAX framework's
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.
The download includes two demos that show how to do the serialization:
JsonSerializationOnServer.aspx, which serializes the array in C# and Visual Basic code; and
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,
- The name is in quotes,
- Name/value pairs are delimited by commas, and
- The name and value are delimited by a colon.
- Arrays are an ordered collection of values encased within square brackets and with each name/value pair delimited by a comma.
- Strings are text encased in quotation marks;
- Numbers are the digits that make up the number;
- The two boolean values are the tokens true and false; and
- The null value is the token null.
| || |
Reading JSON Message in JS - Syntax
| || |
| || |
Thanks & Regards,
Arun Manglick || Senior Tech Lead