我开始与面向对象编程(OOP)和想知道:什么是序列化的意义在面向对象的说法?
当前回答
序列化是将对象转换为可存储的位序列。
所以你可以保存这个序列到一个文件,db或通过网络发送。
稍后,您可以将其反序列化为实际对象,并在需要时重用它。
Web服务和AJAX是序列化最常见的例子。对象在向客户端发送响应之前被序列化。
其他回答
只要考虑一下下面的想法就能理解它。
序列化:
"hello world".split() returns ['hello', 'world']
反序列化:
" ".join(['hello', 'world']) returns "hello world"
序列化必须将二进制对象转换为XML(或其他字符串)表示形式,以便将其存储在数据库/文件中或通过web服务调用通过网络发送。反序列化是相反的过程——将XML/字符串转换回对象。
Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization. ... This illustration shows the overall process of serialization ... Through serialization, a developer can perform actions like sending the object to a remote application by means of a Web Service, passing an object from one domain to another, passing an object through a firewall as an XML string, or maintaining security or user-specific information across applications
从https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/serialization/
(强调我的)
序列化是将数据转换为由字节组成的线性“字符串”。
其他人或多或少也说过同样的事情,但我强调计算机模型要求数据适合一维寻址RAM或持久存储。
大多数“数据”本质上是可序列化的(即使你必须将抽象模型简化为线性模型);不可序列化的是网络连接或复杂的基于状态的机器,如解析器。
序列化是将对象转换为可存储的位序列。
所以你可以保存这个序列到一个文件,db或通过网络发送。
稍后,您可以将其反序列化为实际对象,并在需要时重用它。
Web服务和AJAX是序列化最常见的例子。对象在向客户端发送响应之前被序列化。