public void TestSerializer()
        {
            TempTestClass classA = new TempTestClass
            {
                ID   = 1,
                Name = "NNN",
                Arr  = new int[] { 1, 2, 3 }
            };

            string json  = SampleJsonSerializaer.Serialize(classA, typeof(TempTestClass));
            string json2 = SampleJsonSerializaer.Serialize <TempTestClass>(classA);

            Assert.True(json == json2);//序列化是否成功

            TempTestClass classB = SampleJsonSerializaer.DeSerialize(json2, typeof(TempTestClass)) as TempTestClass;
            TempTestClass classC = SampleJsonSerializaer.DeSerialize <TempTestClass>(json);

            Assert.True(Compare(classA, classB) && Compare(classA, classB));//反序列化是否成功

            json   = json.Replace("NNN", "A");
            classB = SampleJsonSerializaer.DeSerialize <TempTestClass>(json);
            classC = SampleJsonSerializaer.DeSerialize <TempTestClass>(json2);

            Assert.False(Compare(classB, classC));//修改json的情况下是否正确
        }
Beispiel #2
0
 /// <summary>
 /// 保存配置信息
 /// </summary>
 public static void SaveConfig()
 {
     FileHelper.TryWriteAllText("Config.json", SampleJsonSerializaer.Serialize <Configuration>(Config));
 }