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