1.序列化為二進位製流
view code?
using
system;
using
system.collections.generic;
using
system.text;
using
system.runtime.serialization.formatters.binary;
using
system.io;
namespace
common.serialization.byte
memorystream ms =
new
memorystream();
try
finally
}
///
/// 二進位製流轉換為物件
///
/// 二進位製流快取
/// 反序列化後的物件
public
static
object
deserialize(
byte
buffer)
memorystream ms =
new
memorystream(buffer);
try
finally
}
}
}
2.序列化為xml
view code?
using
system;
using
system.text;
using
system.io;
namespace
common.serialization.xml
memorystream ms =
new
memorystream();
try
finally
}
///
/// xml字串轉換為物件
///
/// xml字串
/// 要反序列化為的物件型別
/// 反序列化後的物件
public
static
object
deserialize(
string
xml, type targettype)
memorystream ms =
new
memorystream(encoding.default.getbytes(xml));
try
finally
}
}
}
3.序列化為json?
using
system;
using
system.text;
using
system.io;
using
system.runtime.serialization.json;
namespace
common.serialization.json
memorystream ms =
new
memorystream();
try
finally
}
///
/// json字串轉換為物件
///
/// json字串
/// 要反序列化為的物件型別
/// 反序列化後的物件
public
static
object
deserialize(
string
json, type targettype)
memorystream ms =
new
memorystream(encoding.utf8.getbytes(json));
try
finally
}
}
}
物件序列化與反序列化
using system using system.text using system.collections.generic using system.io using system.runtime.serialization.formatters.binary class serializabl...
物件序列化與反序列化
我們常常需要將一些程式當前資訊儲存在檔案中,如果明文儲存,那麼資訊不安全,使用物件序列化和反序列化可解決此問題 1 將需要儲存的資訊封裝成類,用serializable標記 serializable 次標記必須,以宣告此student類可執行序列化操作 class student public st...
物件序列化 反序列化
必須新增引用 using system.io using system.runtime.serialization using system.runtime.serialization.formatters.binary 方法 region 物件序列化 物件序列化 任意物件 字串 public st...