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
{
Ïà¹ØÎĵµ£º
DateTime dt = DateTime.Now;
//±¾ÔµÚÒ»Ììʱ¼ä
DateTime dt_First = dt.AddDays(-(dt.Day) + 1);
Label1.Text = dt_First.ToString("yyyy-MM-dd");
//½«±¾ÔÂÔÂÊý+1
DateTime dt2 = dt.AddMonths(1);
//±¾ÔÂ×îºóÒ»Ììʱ¼ä
DateTime dt_Last = dt2.AddDays( ......
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Sy ......
ÒëÎÄÔÎĵØÖ·
http://www.cnblogs.com/hl13571/archive/2008/01/28/1056671.html
Ó¢ÎÄÔÎĵØÖ·
Understanding Single Sign-On in ASP.NET 2.0
Àí½âASP.NET 2.0Öеĵ¥µãµÇ¼
Published: 16 Jan 2008
ÕªÒª
ÔÚÕâƪÎÄÕÂÖУ¬MasoudÌÖÂÛÁËÓ¦ÓÃASP.NETÖÐͳһÉí·ÝÑé֤ģÐͽøÐпçÓ¦ÓóÌÐòÑéÖ¤µÄÎÊÌ⣬°üÀ¨£ºMembership Prov ......
¾³£ÒªÐ´Ò»Ð©.netµÄ³ÌÐò£¬¶ÔÓÚÊý¾Ý¿âµÄ·À×¢ÈëÒªÇóÒª±È½Ï¸ß¡£ÕâʱÎÒ´ÓÍøÉÏËÑÁËһЩ´úÂë¡£²é¿´ÁËÒ»ÏÂÖ÷ÒªÊÇͨ¹ýHTTPModelÀ´½øÐжԿͻ§¶Ëת¹ýÀ´µÄÊý¾Ý½øÐд¦Àí¡£
ÔÚ·þÎñÆ÷°²È«À¸Ä¿ÀïÎÒд¹ýһƪ¡¶ÆƽâͨÓÃSql·À×¢Èë·½·¨¡·µÄÎÄÕÂÖÐ˵µ½£¬Ò»Ð©Í¨ÓõķÀ×¢Èë·½·¨ÖÐûÓжÔcookieÊý¾Ý½øÐйýÂË£ ......