我需要特定数据结构的名称
我不断遇到某种数据结构,并想知道它是否有一个名称。它与 JSON 非常接近,但不完全一样。规则是:
- 它完全由映射、数组和基元组成。
- 它是分层的。映射包含名称/值对,其中值可以 可以是另一个映射、数组或基元。数组包含具有相同规则的值。
- 顶层始终是一张地图。
- 原语是字符串、整数、浮点数、布尔值,也可能是 日期。
- 有时映射只是无序的哈希,有时是顺序 名称/值对的数量很重要。
这是一个非常非常有用的结构。您可以使用它来表示文档、数据库记录、各种消息、http 请求以及很多东西。我在 Freemarker(作为“数据模型”)、Mongo 以及任何使用 JSON 的东西中都遇到过它。
它并不是真正的 JSON,因为它是一种文件格式,而不是特定数据结构的规范。它不是一个“对象”,因为对象树可以指向其他东西,比如流和函数。它不是 DOM。
它是什么?
在办公室里,我们开始称其为“garg”,意为“广义论证”。
I keep running into a certain kind of data structure, and wonder if there is a name for it. It maps very closely to JSON, but not exactly. The rules are:
- It is composed entirely of maps, arrays, and primitives.
- It is hierarchical. Maps contain name/value pairs, where a value can
be another map, an array, or a primitive. Arrays contain values with the same rules. - The top level is always a map.
- The primitives are strings, integers, floats, booleans, and possibly
dates. - Sometimes the map is just an unordered hash, and sometimes the order
of the name/value pairs matter.
This is a really, really useful structure. You can use it to represent documents, database records, various messages, http requests, lots of stuff. I've run into it in Freemarker (as the 'data model'), Mongo, and anything that uses JSON.
It's not really JSON, because that's a file format, not a specification for a particular data structure. It's not an "object", because object trees can point to other things, like streams and functions. It's not a DOM.
What is it?
Around the office, we've started to call it a "garg", for "generalized argument".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
它可能不是 JSON(因为规范包含语法规则),但您的结构定义定义了与 JSON 相同的数据结构。
我认为命名这个结构没有用。当您谈论数据时,只需将其称为数据。当您需要交换数据时,您需要数据交换格式。现在 JSON 被证明是一种非常好的方法。
It might not be JSON (since the specs include syntax rules), but your structure definition defines the same data structure as JSON does.
I don't think it's useful to name this structure. When you are talking about data, just call it data. When you need to interchange data you need a data-interchange format. Now JSON proves to be one damn good one.
JSON 不仅仅是一种文件格式。 JSON也是一种数据结构。
来自 JSON.org
JSON isn't just a file format. JSON is also a data structure.
From JSON.org
它是一种承载分层数据的通用数据存储结构。我没有它的通用名称,但如果我要在 C++ 中实现这样一个野兽,我可能会将抽象基类称为
Variant
,并命名具体类型按它们的名称:Integer
、Array
、Map
等。我会将它们放入与我使用位置相关的命名空间中它们 - 或者也许我会为类型本身添加前缀。我也见过这样的结构,但我不知道是否有我认识的名字。DataStore
、Environment
、StorageBin
或任何通用且暗示数据存储的东西都可以。不过,我不认为自己会调用这样的类层次结构
JSON
。如果需要的话,我会提供一个 JsonSerializer 或类似的东西来将此数据映射到 JSON。It is a generic data storage structure that carries around hierarchical data. I don't have a generic name for it, but if I were to implement such a beast in, say, C++, I'd probably call the abstract base class a
Variant
, and name the concrete types by their names:Integer
,Array
,Map
, etc. I'd chuck them in a namespace that would relate to where I'd use them - or maybe I'd prefix the types themselves. I've seen such structures used as well, but I don't know if there is a name that I'd recognize. ADataStore
,Environment
,StorageBin
, or anything that is generic and implies storage of data would do.I don't see myself calling such a class hierarchy
JSON
, though. I would provide aJsonSerializer
or some such to map this data to JSON, if I needed it.听起来您正在描述一个具有可选顺序的 关联数组。
这就是 JSON 所代表的内容,只不过(我相信)JSON 不强加排序要求。当然,许多其他表示形式也描述关联数组,这就是 JSON 成为流行的文本序列化的原因。
更新 1:JSON 并不是一个正确的关联数组。它是对对象属性的描述。因为它经常被解释为关联数组,所以很多人都犯了和我一样的错误。事实上,“对象表示法”才是它的正确名称——惊喜、惊喜。 :) 此外,JSON 不是一种文件格式 - 它是一种文本序列化或标记语言,这与文件格式不同。
It sounds like you're describing an associative array, with optional ordering.
That's what JSON represents, except that (I believe) JSON doesn't impose an ordering requirement. Naturally, many other representations also describe associative arrays, which is why JSON is a popular text serialization.
Update 1: JSON isn't properly an associative array. It is a description of object properties. Because it is very often construed as an associative array, many people make the same mistake I did. In fact, "object notation" is the proper name for it - surprise, surprise. :) In addition, JSON isn't a file format - it's a text serialization or markup language, which is different from a file format.
该结构是一棵树,其叶子存储了不同类型的值。
在 Boost 中,类似的结构称为“属性树”。
The structure is a tree with different kinds of values stored at its leafs.
In Boost, a similar structure is called Property Tree.