Skip to content

Instantly share code, notes, and snippets.

@springaki
Created July 10, 2012 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save springaki/3080415 to your computer and use it in GitHub Desktop.
Save springaki/3080415 to your computer and use it in GitHub Desktop.
JSON serialize deserialize Test (JavaScriptSerializer)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Web.Script.Serialization;
namespace ConsoleApplication2
{
[DataContract]
public class Cell
{
public Cell()
{ }
public Cell(
string row,
string col)
{
Row = int.Parse(row);
Col = int.Parse(col);
}
[DataMember]
public int Row { get; set; }
[DataMember]
public int Col { get; set; }
}
class Program
{
static void Main(string[] args)
{
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var dic = new Dictionary<string, Cell>();
dic.Add("aaa", new Cell("1", "2"));
dic.Add("bbb", new Cell("111", "33"));
string json = serializer.Serialize(dic);
Dictionary<string, Cell> deseri = serializer.Deserialize<Dictionary<string, Cell>>(json);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment