Wednesday, 2 May 2012

C# JSON Serializer

Add Reference to System.Web.Extensions

[Test]
public void Test()
{
    var serializer = new JavaScriptSerializer();
    var input = new SerializationTest() { Id = 1 };
    var text = serializer.Serialize(input);
    Console.WriteLine(text);
    var output = serializer.Deserialize<SerializationTest>(text);
    Console.WriteLine("Id: {0}", output.Id);
}
class SerializationTest
{
    public int Id { get; set; }
}

No comments:

Post a Comment