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

JSON in ASP.NET Ajax: First words ...

Let is make it clear from the start: JSON does deserve a top spot in such a list, if nothing else because it is the skeleton that keeps the whole AJAX paradigm on its feet. Even more so for us .NET programmers. In fact, we would be more accurate if we called it AJAJ, although I agree that would feel quite stupid . As a matter of fact, when using ASP.NET AJAX, most of the communication between client and server is serialized in JSON format rather than XML, at least when using the default settings. And there is good reason for that.

In fact, JSON is a very simple human-readable, easily-parsable data-interchange format, like XML, but unlike the latter, it is very concise, and, more importantly, it is immediately convertible to a Javascript object. That is, if you simply eval() a JSON expression, you get returned the actual object that was serialized in the first place.

For those of you who might not know it, eval() is a built-in javascript function that evaluates a string and executes it as a line of code (see here for more info).

For example, you might serialize a very simple "Person" object that has properties "firstName", "lastName", and "age" as follows:

{"firstName":"Marco","lastName":"Anastasi","age":27}

Note that property names are always enclosed in double quotes, while values follow the usual javascript syntax.

In Javascript, you would then be able to use code like this:


var json = {"firstName":"Marco", "lastName":"Anastasi", "age":27};

var person = eval(( + json + ));

alert(person.firstName);

Note that we enclose the json expression we are evaluating in parentheses, to instruct eval() to treat the string as an expression rather than a block of code.

WARNING: what you see here is merely used as an example. You should avoid resorting to the eval() function in a production environment, because of potential security breaches.

In my next posts I will talk profusely about one of the possible solutions to this problem (and probably the one that ASP.NET developers are keener to use), i.e. ASP.NET AJAX is built-in client side JSON serializer/deserializer.

What you have seen so far is obviously a very simplified introduction to JSON, and doesn show much of what you might achieve by leveraging its power and simplicity. In my next post, I will delve deeper into its inner workings and how to use it to manage the communication between client side script and a server-side application, and finally to retrieve information from web services, shape it into different formats and serve it to the client browser.

source: geekswithblogs

 Original Source:

AddThis Social Bookmark Button

Posted at 08:49:45 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.

Top Stuff

MessengerFX

e-messenger

ILoveIM

Top 20 Ruby CMS

eBuddy

MSN Web Messenger



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.


Search


Topics

  • .Net (162)
  • Ajax (82)
  • Ajax Games (10)
  • Articles (95)
  • Bookmarking (35)
  • Calendar (20)
  • Chat (45)
  • ColdFusion (3)
  • CSS (75)
  • Email (23)
  • Facebook (83)
  • Flash (19)
  • Google (54)
  • Html (27)
  • Image (11)
  • International Calls & VOIP (7)
  • Java (54)
  • Javascript (265)
  • jQuery (159)
  • JSON (61)
  • Perl (2)
  • PHP (156)
  • Presentation (19)
  • Python (3)
  • Resources (2)
  • RSS (8)
  • Ruby (29)
  • Storage (4)
  • Toolkits (103)
  • Tutorials (217)
  • UI (11)
  • Utilities (174)
  • Web2.0 (18)
  • XmlHttpRequest (28)
  • YUI (12)

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