Newtonsoft的序列化和反序列化


   class test
    {
        public string a;
       public int b;
        public byte[] c;
        public IntPtr d;
    }

把上面对象序列化成string并保存。

  test t=new test() { a = "aa", b = 444, c = new byte[] { 2, 1, 23,200,11,32,3,4,43,23,7 }, d = (IntPtr) 50 };
 string m = Newtonsoft.Json.JsonConvert.SerializeObject(t);

 

如果test对象的成员发生更改,则反序列化时,新增的成员默认为null,已删除的成员不处理,整个程序不会报错。

如类改成:

    class test
    {
        public string tt;
        public string a;
       // public int b;
        public byte[] c;
        public IntPtr d;
    }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM