yaml json_数据序列化比较:JSON,YAML,BSON,MessagePack

yaml json

Data Serialization Comparison

JSON is the de facto standard for data exchange on the web, but it has its drawbacks, and there are other formats that may be more suitable for certain scenarios. I’ll compare the pros and cons of the alternatives, including ease of use and performance.

JSON是Web上数据交换的事实上的标准,但是它有缺点,并且还有其他格式可能更适合某些情况。 我将比较替代方案的优缺点,包括易用性和性能。

Note: I won’t cover implementation details here, but if you’re a Ruby programmer, check out this article, where Dhaivat writes about implementing some serialization formats in Ruby.

注意:我不会在这里介绍实现细节,但是,如果您是Ruby程序员,请查阅本文 ,Dhaivat在其中撰写了有关在Ruby中实现某些序列化格式的文章。

什么是数据序列化 (What Is Data Serialization)

According to Wikipedia, serialization is:

根据Wikipedia ,序列化为:

the process of translating data structures or object state into a format that can be stored (for example, in a file or memory buffer, or transmitted across a network connection link) and reconstructed later in the same or another computer environment.

将数据结构或对象状态转换为可以存储的格式(例如,存储在文件或内存缓冲区中,或通过网络连接链接传输)并稍后在相同或另一个计算机环境中重建的格式的过程。

Let’s say you want to collect certain data about a group of people — name, last name, nickname, date of birth, instruments they play. You could easily set a spreadsheet, define some columns, and make every row an entry. You could go just a little further, define that the date of birth column must be a number, and that the instruments columns could be a list of options. It’d look like this:

假设您想收集有关一群人的某些数据,例如姓名,姓氏,昵称,出生日期,他们演奏的乐器。 您可以轻松地设置电子表格,定义一些列,并将每一行作为一个条目。 您可以走得更远一点,定义“生日”列必须为数字,并且“工具”列可以为选项列表。 看起来像这样:

name last name dob nickname instruments
William Bailey 1962 Axl Rose vocals, piano
Saul Hudson 1965 Slash guitar
名称 多宝 昵称 仪器
威廉 贝利 1962年 Axl玫瑰 人声,钢琴
扫罗 哈德森 1965年 削减 吉他

More or less, what you did there was to define a data structure; and you’ll do just fine if you only need this on a spreadsheet format. The problem is that, if you ever want to exchange this information with a database or a website, the mechanics by which these data structures are implemented on these other platforms — even if the underlying semantics are overall the same — will be dramatically different. You can’t just plug-n-play a spreadsheet into a web application, unless the application has been specifically designed for it. And you can’t transfer that info from the website to the database unless you have some sort of export tool or gateway for it.

或多或少,您所做的就是定义一个数据结构 。 如果只需要在电子表格格式中使用它,那就会很好。 问题是,如果您想与数据库或网站交换此信息,则即使在基本语义上完全相同,在其他平台上实现这些数据结构的机制也会大不相同。 您不能只是将电子表格即插即用到Web应用程序中,除非该应用程序是专门为此设计的。 而且,除非您具有某种导出工具或网关,否则您无法将该信息从网站传输到数据库。

Let’s assume that our website already has these data structures implemented in its internal logic, and that it just cannot deal with a spreadsheet format. In order to solve these problems, you can translate these data structures into a format that can be easily shared across different applications, architectures, or what have you: you serialize them. And by doing so, you ensure not only that you can transfer this data across platforms, but that they can be reconstructed in the reverse process called deserialization. Furthermore, if exchanged back from the website to the spreadsheet, you’ll get a semantically identical clone of the original object — that is, a row that looks exactly the same as the one you originally sent.

假设我们的网站已经在内部逻辑中实现了这些数据结构,并且无法处理电子表格格式。 为了解决这些问题,您可以将这些数据结构转换为可以在不同应用程序,体系结构或所拥有的内容之间轻松共享的格式:对它们进行序列化 。 这样,您不仅确保可以跨平台传输此数据,而且还可以以称为反序列化的反向过程来重建它们。 此外,如果从网站交换回电子表格,您将获得原始对象在语义上相同的克隆,即与原始发送的对象看起来完全相同的一行。

In short: serializing data is finding some sort of universal format that can be easily shared across different applications.

简而言之:序列化数据正在寻找某种通用格式,可以在不同应用程序之间轻松共享。

格式 (The Formats)

JSON格式 (JSON)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值