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