riccardod
1/25/2015 - 8:39 PM

gistfile1.cs

using System;
using System.Web.Helpers;
using NUnit.Framework;
using ServiceStack;

namespace Serialization.Tests
{
    [TestFixture]
    public class DeserializationTest
    {
        const string JsonText = @"
                {
                    projects:[
                        {
                            name: ""Project1""
                        },
                        {
                            name: ""Project2""
                        },
                        {
                            name: ""Project3""
                        }
                    ]
                }";
        [Test]
        public void WebHelperDeserialization()
        {

            dynamic data = Json.Decode(JsonText);
            var proj3Name = data.projects[2].name;
            Console.WriteLine(proj3Name);
            Assert.AreEqual(proj3Name, "Project3", "Error deserializing");
        }
        [Test]
        public void ServiceStackDeserialization()
        {
            var data = DynamicJson.Deserialize(JsonText);
            var proj3Name = data.projects[2].name;
            Console.WriteLine(proj3Name);
            Assert.AreEqual(proj3Name, "Project3", "Error deserializing");
        }
    }
}