JSON serialization and deserialization of ASP. NET AJAX

Source: Internet
Author: User

JSON serialization and deserialization

 
 
  1. POST /Ajax/ZipCodeService.asmx/GetCityAndState HTTP/1.1  
  2. Accept: */*  
  3. Accept-Language: en-us  
  4. Referer: http://localhost:1997/Ajax/ZipCodePage.aspx  
  5. UA-CPU: x86  
  6. Accept-Encoding: gzip, deflate  
  7. User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; ...)  
  8. Host: localhost:1997  
  9. Content-Length: 15  
  10. Connection: Keep-Alive  
  11. Cache-Control: no-cache  
  12. {"zip":"98052"}  
  13. HTTP/1.1 200 OK  
  14. Server: ASP.NET Development Server/8.0.0.0  
  15. Date: Fri, 29 Dec 2006 21:06:17 GMT  
  16. X-AspNet-Version: 2.0.50727  
  17. Cache-Control: private, max-age=0 
  18. Content-Type: application/json; charset=utf-8  
  19. Content-Length: 16  
  20. Connection: Close  
  21.  
  22. {"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:

 
 
  1. [ScriptMethod (ResponseFormatResponseFormat=ResponseFormat.Xml)]  
  2. public XmlDocument GetData()  
  3. {  
  4.   ...  

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.

  1. Analysis on ASP. NET Web Security
  2. Session State of ASP. NET
  3. Analysis on the attribute ASP. NET of IsPostBack
  4. ASP. NET architecture and security mechanism
  5. Overview ASP. NET Crystal Reports

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.