Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How to deserialize the object with javaScript deserializer in ScriptEnabled Service call?

user-image
Question added by Kashif Akhter , VP - Wing Head Application Development , National Bank of Pakistan
Date Posted: 2013/04/21
Zaid Rabab'a
by Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.

make josn obj using system.web.script.serialization.javascriptserializer();

Murad Bin Makhashin
by Murad Bin Makhashin , Software Developer , Dar Al Tamleek

To serialize an object to JSON string, you need to use the method System.Web.Script.Serialization.JavaScriptSerializer.Serialize, and pass your object as an argument.
Here is an example (note: in console application project, you might want to add a reference to System.Web): public class Person { public string Name {get; set;} public int Age {get; set;} public List Contacts {get; set;} } public class Program { static void Main(string[] args){ Person p = new Person { Name = "Whoever", Age = 30, Contacts = new List() } p.Contacts.Add("Contact 1"); p.Contacts.Add("Contact 2"); p.Contacts.Add("Contact 3"); var json = new System.Web.Script.Serialization.JavaScriptSerializer() .Serialize(p); Console.WriteLine(json); } } Hope that helps :)

More Questions Like This