• Home
  • New Entries
  • Popular Entries
  • Submit a Story
  • About

Microsoft AJAX Library - Introducing JSON ...

In AJAX applications, client-server communication is usually packed in XML documents, or in the JSON (JavaScript Object Notation) format. Interestingly enough, JSON's popularity increased together with the AJAX phenomenon, although the AJAX acronym includes XML.

View More Info

JSON is the format used by the Microsoft AJAX Library and the ASP.NET AJAX Framework to exchange data between the AJAX client and the server, which is why it deserves a quick look here. As you will learn, the Microsoft AJAX Library handles JSON data packaging through Sys.Serialization.JavaScriptSerializer, which is described in the Appendix—but more on this later.

Perhaps the best short description of JSON is the one proposed by its official website, http://www.json.org: "JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate."

If you are new to JSON, a fair question you could ask would be: why another data exchange format? JSON, just like XML, is a text-based format that it is easy to write and to understand for both humans and computers. The key word in the definition above is "lightweight". JSON data structures occupy less bandwidth than their XML versions.

To get an idea of how JSON compares to XML, let is take the same data structure and see how we would represent it using both standards:

    < ?xml version="1.0" encoding="UTF-8" standalone="yes"? >
    < response >
    < clear >false< /clear >
    < messages >
    < message >
    < id >1< /id >
    < color >#000000< /color >
    < time >2006-01-17 09:07:31< /time >
    < name >Guest550< /name >
    < text >Hello there! What is up?< /text >
    < /message >
    < message >
    < id >2< /id >
    < color >#000000< /color >
    < time >2006-01-17 09:21:34< /time >
    < name >Guest499< /name >
    < text >This is a test message< /text >
    < /message >
    < /messages >
    < /response >
    The same message, written in JSON this time, looks like this:
    [
    {"clear":"false"},
    "messages":
    [
    {"message":
    {"id":"1",
    "color":"#000000",
    "time":"2006-01-17 09:07:31",
    "name":"Guest550",
    "text":"Hello there! What is up?"}
    },
    {"message":
    {"id":"2",
    "color":"#000000",
    "time":"2006-01-17 09:21:34",
    "name":"Guest499",
    "text":"This is a test message"}

    }
    ]
    }
    ]

As you can see, they aren very different. If we disregard the extra formatting spaces that we added for better readability, the XML message occupies 396 bytes while the JSON message has only 274 bytes.

JSON is said to be a subset of JavaScript because it is based on the associative array-nature of JavaScript objects. JSON is based on two basic structures:

    * Object: This is defined as a collection of name/value pairs. Each object begins with a left curly brace ({) and ends with a right curly brace (}). The pairs of names/values are separated by a comma. A pair of name/value has the following form: string:value.
      .
    * Array: This is defined as a list of values separated by a coma (,).

We have mentioned strings and values. A value can be a string, a number, an object, an array, true or false, or null. A string is a collection of Unicode characters surrounded by double quotes. For escaping, we use the backslash ().

It is obvious that if you plan to use JSON, you need to be able to parse and generate JSON structures in both JavaScript and ASP.NET, at least if the communication is bidirectional. JSON libraries are available for most of today is programming languages: ActionScript, C, C++, C#, VB.NET, Delphi, E, Erlang, Java, JavaScript, Lisp,Lua, ML and Ruby, Objective CAML, OpenLazslo, Perl, PHP, Python, Rebol, Ruby, and Squeak. When we said almost every programming language we were right, weren we!
source: exforsys

 View Full Story.
Posted at 10:32:57 am | Permalink | Posted in JSON  

Related Stuff

  • MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.

  • Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone

  • TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support

  • ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.

  • Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.

  • Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software

  • PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.

Be the first ... |Add your comment.

Your Comment ...

  Name (required)

  Email (required, hidden)

  Website


About Ajaxlines

Ajaxlines is a project focused on providing its audience with a database of most of Ajax related articles, resources, tutorials and services from around the world.

Its purpose is to showcase the power of Ajax and to act as a portal to the Ajax development community.


Recent Stuff

Using ASP.NET AJAX JSON Asynchronous Web Services

Growl for Windows and a Web Notification API

Learn AJAX from Scratch - Part II

Learn AJAX from Scratch - Part I

PHP AJAX CHAT, Bug fixes - including weird mozilla bug

Learn PHP From Scratch


Our Partners

Ajax Projects

Web 2.0 Sites

Webloglines

Human Development Handbook

Software Development Company

Ajaxlines


Search


Topics

  • .Net (96)
  • Articles (76)
  • Bookmarking (35)
  • Calendar (18)
  • Chat (38)
  • ColdFusion (3)
  • CSS (30)
  • Email (23)
  • Flash (13)
  • Games (6)
  • Google (17)
  • Html (6)
  • Image (11)
  • International Calls & VOIP (7)
  • Java (34)
  • Javascript (146)
  • JSON (16)
  • Perl (2)
  • PHP (82)
  • Presentation (19)
  • Python (3)
  • Resources (1)
  • RSS (1)
  • Ruby (7)
  • Storage (4)
  • Toolkits (87)
  • Tutorials (190)
  • UI (11)
  • Utilities (161)
  • Web2.0 (13)
  • XmlHttpRequest (18)
  • YUI (4)

© 2006 www.ajaxlines.com. All Rights Reserved. Powered by IRange