Created
July 10, 2012 01:24
-
-
Save springaki/3080415 to your computer and use it in GitHub Desktop.
JSON serialize deserialize Test (JavaScriptSerializer)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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