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;
    }

posted @ 2018-11-21 09:22  81  阅读(2841)  评论(0编辑  收藏  举报