Tuesday, March 6, 2012

Working with JSON using C# (.NET 3.5 or above)

Using .NET framework 3.5 or above, one can manipulate JSON object using a JavaScriptSerializer. To do so:
  1. Adding .NET reference System.Web.Extensions
  2. Use namespace System.Web.Script.Serialization
  3. Create appropriate classes to describe the target JSON structure
The following example demonstrates how to read from and write to a JSON object.

Note: The JSON string used below is adopted from web.

P.S. In C#, two double quotes are used to describe one double quote in a multi-line literal (string), all escape characters (e.g. \") does not work in this case

No comments:

Post a Comment