我开始与面向对象编程(OOP)和想知道:什么是序列化的意义在面向对象的说法?
看看这个,它会给你一个很好的解释:
http://en.wikipedia.org/wiki/Serialization
我认为序列化这个术语最常见的用法是将二进制对象转换为XML(或其他字符串)表示形式,这样它就可以存储在数据库/文件中,或者在web服务调用中通过网络发送。反序列化是相反的过程——将XML/字符串转换回对象。
编辑: 您可能遇到的另一个术语是编组/解组。编组基本上是与序列化相同的概念,而解组与反序列化相同。
序列化是指当对象的状态可以保存在文件中时,对象(内存块)转换为一种形式(例如)。
就像做饼干一样,对象是一个面团,饼干是一个序列化的面团。
所以通过“序列化”,你可以把cookie发送给你的朋友。
就像这样:-)
序列化是将对象转换为可存储的位序列。
所以你可以保存这个序列到一个文件,db或通过网络发送。
稍后,您可以将其反序列化为实际对象,并在需要时重用它。
Web服务和AJAX是序列化最常见的例子。对象在向客户端发送响应之前被序列化。
序列化是将数据转换为由字节组成的线性“字符串”。
其他人或多或少也说过同样的事情,但我强调计算机模型要求数据适合一维寻址RAM或持久存储。
大多数“数据”本质上是可序列化的(即使你必须将抽象模型简化为线性模型);不可序列化的是网络连接或复杂的基于状态的机器,如解析器。
序列化必须将二进制对象转换为XML(或其他字符串)表示形式,以便将其存储在数据库/文件中或通过web服务调用通过网络发送。反序列化是相反的过程——将XML/字符串转换回对象。
序列化只不过是将Java支持的对象转换为文件支持的形式
(OR)
将Java支持的形式转换为网络支持的形式..序列化的主要范围只是将数据从一层传输到另一层…只有序列化的对象,我们可以通过网络发送。
When instantiating (constructing) the actual object(the thing) from a class (blueprint) there is a need to save the object (thing) by serializing it (breaking it down to its basic atomic structure) to a space in memory. (Kind of like Star Treks Transporter). You break the thing down into it stream of information that can be transported somewhere and stored. Then when you want to reconstruct the thing you just pull the atomically stored instance back into the object. Different from instaniation.
简单地说,序列化是一个将对象转换为字节流的过程,这样它就可以通过网络传输或存储在持久存储器中。
反序列化则完全相反——从网络或持久化存储中获取字节流,并将其转换回具有相同状态的Object。
需要理解的是如何解释或操作这些字节流,以便我们得到完全相同的对象/相同的状态。有很多方法可以实现这一点。其中一些是-
XML: Convert Object to XML, transfer it over a network or store it in a file/db. Retrieve it and convert it back to the object with same state. In Java we use JAXB(Java architecture for XML binding) library.(From java 6 it comes bundled with JDK). JSON: Same can be done by converting the Object to JSON (JavaScript Object notation). Again there is GSON library that can be used for this. Or we can use the Serialization that is provided by the OOP language itself. For example, in Java you can serialize an Object my making it implement Serializable interface and writing to Object Stream.
序列化是将Java、c#或任何其他(OOP语言)支持的对象转换为可移植形式的过程。通过这种方式,它可以通过网络传输或存储在磁盘上。对于可序列化的类,它必须实现可序列化的接口。
什么是序列化?
图片类比解释:
简介:
序列化意味着将某物(例如我的狗Rex)转换成一系列的1和0 -可以运输/存储等。我的海外朋友可以把这些1和0翻译成小狗的完美表现(反序列化)。
类比澄清
朋友们,这是个类比。我认为你还不能连载一只小狗。您可以序列化数据结构或其他复杂对象。(我写这个答案是为了让您能够以一种有趣的方式,在不到3秒的时间内理解这个概念,而不用绞尽脑汁去理解一个核心的技术定义),但如果您更喜欢一个规范的定义,请查看维基百科关于序列化的条目。
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/
(强调我的)
只要考虑一下下面的想法就能理解它。
序列化:
"hello world".split() returns ['hello', 'world']
反序列化:
" ".join(['hello', 'world']) returns "hello world"
推荐文章
- 为什么不使用异常作为常规的控制流呢?
- 什么是序列化?
- 我如何复制一个哈希在Ruby?
- 每个递归都可以转换成迭代吗?
- 为什么生成较长的serialVersionUID而不是简单的1L?
- 将流转换为字符串并返回
- 什么是ORM,它是如何工作的,我应该如何使用它?
- 我能在服务器端应用程序(PHP、Ruby、Python等)上读取URL的哈希部分吗?
- 多少个参数是太多?
- Parcelable遇到IOException写入序列化对象getactivity()
- 对于不可变集合上的非突变“add”方法,最好的名称是什么?
- foo到底是什么意思?
- 不带空格的Python - json
- 打印对象的所有属性
- foreach和map有区别吗?