几种常见结构化数据的比较

在我刚接触windows编程的时候,通常用.ini文件。web

后来,都是本身定义数据格式,本身实现数据的读写。编程

再后来,就是xml了,那时我比较习惯使用tinyXml。json

如今呢?你们都在用Json。windows

为了追求性能,很多人已经将目光投向了protobuf和flatbuffer。less

IT行业的变化就是这般的快。做为IT从业者,资讯这一块是要重视的。编程语言


老古董就不提了,让考古学家去深掘吧。本文讨论的是xml,json和protobuf,stackoverflow上找到了个不错的总结性能

Jsonspa

. human readable/editableexcel

. can be parsed without knowing schema in advancecode

. excellent browser support

. less verbose than xml


XML

. human readable/editable

. can be parsed without knowing schema in advance

. standard for SOAP etc-------------?

. good tooling support

. pretty verbose


Protobuf

. very dense data

. hard to robustly decode without knowing the schema(data format is internally ambiguous, and needs schema to clarify)

. very fast processing

. not intended for human eyes(dense binary)


All have good support on most platforms.

Personally, I rarely use xml these days. If the consumer is a browser or a public API I tend to use json. For internal APIs I tend to use protobuf for performance.

我的的见解是:

1. 相对于xml,Json的结构更贴近于面向"对象"编程。Json更加简洁,表达一样的意思,json的字节数更少,须要传输的内容更少,相对更快。

2. 为何要用protobuf?相对Json,它有什么优势?

    protobuf是二进制形式的,字节占用更小,速度更快。同时protobuf支持多种编程语言,方便数据交换,版本兼容性

相关文章
相关标签/搜索