JSON serialization and deserialization
- POST /Ajax/ZipCodeService.asmx/GetCityAndState HTTP/1.1
- Accept: */*
- Accept-Language: en-us
- Referer: http://localhost:1997/Ajax/ZipCodePage.aspx
- UA-CPU: x86
- Accept-Encoding: gzip, deflate
- User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; ...)
- Host: localhost:1997
- Content-Length: 15
- Connection: Keep-Alive
- Cache-Control: no-cache
- {"zip":"98052"}
- HTTP/1.1 200 OK
- Server: ASP.NET Development Server/8.0.0.0
- Date: Fri, 29 Dec 2006 21:06:17 GMT
- X-AspNet-Version: 2.0.50727
- Cache-Control: private, max-age=0
- Content-Type: application/json; charset=utf-8
- Content-Length: 16
- Connection: Close
-
- {"REDMOND", "WA"}
JSON is an emerging industry standard serialization format. It is also the native format used by ASP. net ajax. Microsoft AJAX Library's Sys. Serialization. JavaScriptSerializer class supports JSON Serialization and deserialization on the client. The System. Web. Script. Serialization. JavaScriptSerializer class supports JSON Serialization and deserialization on the server.
Not all types are JSON compatible. For example, JSON cannot process objects with circular references. When you need to return complex data types that are not compatible with JSON, you can use the ScriptMethod attribute of ASP. net ajax to serialize the return type to XML. This technique is also useful for returning XML data, as shown below:
- [ScriptMethod (ResponseFormatResponseFormat=ResponseFormat.Xml)]
- public XmlDocument GetData()
- {
- ...
- }
In addition, you can build and register a custom JSON converter that allows serialization and deserialization of types that are generally not compatible with JSON. ASP. net ajax January Futures CTP contains three such converters: one for DataSet, one for DataTable, and the other for DataRow.
- Analysis on ASP. NET Web Security
- Session State of ASP. NET
- Analysis on the attribute ASP. NET of IsPostBack
- ASP. NET architecture and security mechanism
- Overview ASP. NET Crystal Reports