解析jason(2)-Dictionary

直接上代码:

  class Program
{
    class aaa
    {
        public int a;
        public string b;

        public override string ToString()
        {
            return "b:" + b + "  a:" + a;
        }
    }
    static void Main(string[] args)
    {
       
        JavaScriptSerializer serializer = new JavaScriptSerializer();

        Dictionary kkkk = new Dictionary();
        kkkk[0] = new aaa() { a=0,b="a"};
        kkkk[1] = new aaa() { a = 1, b = "b" };
        kkkk[2] = new aaa() { a = 2, b = "c" };

        var v = kkkk.ToDictionary(de => serializer.ConvertToType(de.Key), de => de.Value);

        string Contentjson = serializer.Serialize(v);
        Console.WriteLine(Contentjson);

        Dictionary tt = serializer.Deserialize>(Contentjson);
        var vv = tt.ToDictionary(de => serializer.ConvertToType(de.Key), de => de.Value);
        foreach (var j in vv)
        {
            Console.WriteLine("key:" + j.Key + "   " + j.Value.ToString());
        }
        Console.Read();
    }
}

你可能感兴趣的:(解析jason(2)-Dictionary)