April 2009 Blog Posts

json serialization in ajax net both client side and server side

14 April 2009 |

JSON objects representations are small and lightweight compared to XML they are now the core of AJAX.net services serialization. in AJAX.net they work out of the box

you can serilaize/deserialize  your objects to JSON using this snippet of server side code

using System.Web.Script.Serialization;
JavaScriptSerializer jss = new JavaScriptSerializer();
//Serialize
jss.Serialize(object);
//Deserialize
yourCustomType result = jss.Deserialize(yourJSONString);

 

and on the client side you can do the same as long as you have a script manager in your page

// Serialization
var jsonString= Sys.Serialization.JavaScriptSerializer.serialize(JSObject);
//deserialization 
var JSObject= Sys.Serialization.JavaScriptSerializer.deserialize(jsonString);