幾種常見結構化數據的比較

在我剛接觸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支持多種編程語言,方便數據交換,版本兼容性

相關文章
相關標籤/搜索