JSON Serialization and Deserialization in ASP.Net
JSON Serialization and Deserialization in ASP.Net
I was looking around for a simple example which would just do an object serialization to a JSON format, and then deserializing back to the original object. I found few examples on MSDN, but did seem to be too long to try. Here I've given a simple code which would make your understanding easy, and simpler.
What is JSON?
JSON is another format of expressing data, just like XML. But, JSON is very simpler than XML, and tiny than XML. So, it is becoming popular in the web world to choose the JSON notation over XML since JSON notation are usually shorter, and less data to be transmitted if at all they were to be.
Okay, I understood a little about JSON. Give me an example!
I know an example will get your understanding much better. Below is a simple example of how an object can be expressed in JSON notation. Let's take a classical example of a Person object, and expressing myself as an object.
{
"firstName": "Rakki",
"lastName":"Muthukumar",
"department":"Microsoft PSS",
"address": {
"addressline1": "Microsoft India GTSC",
"addressline2": "PSS - DSI",
"city": "Bangalore",
"state": "Karnataka",
"country": "India",
"pin": 560028
}
"technologies": ["IIS", "ASP.NET","JavaScript","AJAX"]
}
In the above example, address is another object inside my Person, and technologies is an array or strings.
Express this as a simple .NET class, please!
Here is a simple example.
public class Address
{
public string addressline1, addressline2, city, state, country;
public int pin;
}
public class Person
{
Ïà¹ØÎĵµ£º
ASP.NET AJAX Timer ¿Ø¼þ°´¶¨ÒåµÄʱ¼ä¼ä¸ôÖ´Ðлط¢¡£Èç¹û½« Timer ¿Ø¼þÓÃÓÚ UpdatePanel ¿Ø¼þ£¬Ôò¿ÉÒÔ°´¶¨ÒåµÄʱ¼ä¼ä¸ôÆôÓò¿·ÖÒ³¸üС£Ò²¿ÉÒÔʹÓà Timer ¿Ø¼þÀ´·¢ËÍÕû¸öÒ³Ãæ¡£
µ±ÄúÒªÖ´ÐÐÒÔϲÙ×÷ʱ£¬ÇëʹÓà Timer ¿Ø¼þ£º
·¶¨ÆÚ¸üÐÂÒ»¸ö»ò¶à¸ö UpdatePanel ¿Ø¼þµÄÄÚÈÝ£¬¶øÎÞÐèË ......
ASP.NET Êý¾Ý¿Ø¼þ:GridView,DataList,Repeater ,DetailsView,FormView¡£
ASP.NET Êý¾Ý¿Ø¼þ×ÛÊö£º
1.ǰ3¸öÓÃÓÚ³ÊÏÖ¶àÌõ¼Ç¼,ºóÃæ2¸öÓÃÓÚ³ÊÏÖµ¥ÌõÊý¾ÝÃ÷ϸ,¼´³£ÓõļǼÃ÷ϸ¡£
2.GridViewºÍDetailsView¿Ø¼þµÄ²¼¾Ö¹Ì¶¨,×Ô¶¨ÒåÊý¾ÝÏÔʾµÄ²¼¾Ö¹¦ÄÜÓÐÏÞ,Ò»°ãÊʺϲ¼¾Ö¼òµ¥µÄÊý¾Ý³ÊÏÖ¡£3.DataList,RepeaterºÍFormViewÊý¾Ý¿Ø¼þ ......
Ò»¡¢ÈÏʶWeb.configÎļþ
¡¡¡¡Web.configÎļþÊÇÒ»¸öXMLÎı¾Îļþ£¬ËüÓÃÀ´´¢´æ ASP.NET Web Ó¦ÓóÌÐòµÄÅäÖÃÐÅÏ¢£¨Èç×î³£ÓõÄÉèÖÃASP.NET Web Ó¦ÓóÌÐòµÄÉí·ÝÑéÖ¤·½Ê½£©£¬Ëü¿ÉÒÔ³öÏÖÔÚÓ¦ÓóÌÐòµÄÿһ¸öĿ¼ÖС£µ±Äãͨ¹ýVB.NETн¨Ò»¸öWebÓ¦ÓóÌÐòºó£¬Ä¬ÈÏÇé¿öÏ»áÔÚ¸ùĿ¼×Ô¶¯´´½¨Ò»¸öĬÈϵÄ
&nb ......
¾³£ÒªÐ´Ò»Ð©.netµÄ³ÌÐò£¬¶ÔÓÚÊý¾Ý¿âµÄ·À×¢ÈëÒªÇóÒª±È½Ï¸ß¡£ÕâʱÎÒ´ÓÍøÉÏËÑÁËһЩ´úÂë¡£²é¿´ÁËÒ»ÏÂÖ÷ÒªÊÇͨ¹ýHTTPModelÀ´½øÐжԿͻ§¶Ëת¹ýÀ´µÄÊý¾Ý½øÐд¦Àí¡£
ÔÚ·þÎñÆ÷°²È«À¸Ä¿ÀïÎÒд¹ýһƪ¡¶ÆÆ½âͨÓÃSql·À×¢Èë·½·¨¡·µÄÎÄÕÂÖÐ˵µ½£¬Ò»Ð©Í¨ÓõķÀ×¢Èë·½·¨ÖÐûÓжÔcookieÊý¾Ý½øÐйýÂË£ ......
´ó¼ÒÖªµÀ£¬MicrosoftΪÁ˸üºÃµØÔ¤·À¶ñÒâÓû§ºÍ¹¥»÷ÕߵĹ¥»÷£¬ÔÚĬÈÏÇé¿öÏ£¬Ã»Óн« IIS6.0 °²×°µ½ Windows Server 2003 ¼Ò×åµÄ³ÉÔ±ÉÏ¡£¶øÇÒ£¬µ±ÎÒÃÇ×î³õ°²×° IIS6.0 ʱ£¬¸Ã·þÎñÔڸ߶Ȱ²È«ºÍ"Ëø¶¨"ģʽϰ²×°¡£ÔÚĬÈÏÇé¿öÏ£¬IIS6.0 ֻΪ¾²Ì¬ÄÚÈÝÌṩ·þÎñ¼´£¬ÖîÈç ASP¡¢ASP.NET¡¢ÔÚ·þÎñÆ÷¶ËµÄ°üº¬Îļþ¡¢WebDAV ·¢²¼ºÍ FrontP ......