“JSON 对象”应该是什么?称为?

发布于 2024-12-01 13:19:44 字数 269 浏览 0 评论 0原文

每当这里有人说“我有一个 JSON 对象”时,人们就会(正确地)抱怨“没有 JSON 对象这样的东西!”但是...

您如何称呼可以用 JSON 表示的数据结构类?

它类似于“Map、List、Number、String 和 Boolean 的有限传递闭包”——也就是说,省略了函数之类的东西以及集合和队列之类的更奇特的结构。类别很有用。显然,JSON 中所做的一切都使用它。 CouchDB(我认为其他面向文档的数据库)使用它。大多数非循环数据结构都包含在其中。

但它叫什么?

Whenever someone here says "I have a JSON object", people complain (rightly) that "There's no such thing as a JSON object!" But...

What do you call the class of data structures that could be represented by JSON?

It's something like "the finite transitive closure of Map, List, Number, String, and Boolean" -- that is, omitting things like functions and the fancier structures like sets and queues. The category is useful. Obviously, everything done in JSON uses it. CouchDB (and I think the other document-oriented databases) use it. Most acyclic data structures are contained in it.

But what it is called?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

那小子欠揍 2024-12-08 13:19:44

JSON 只是一种可以轻松转换为 Javascript 对象的表示法。当 JSON 在 Javascript 中具体化(评估)时,它会变成 Javascript 对象/关联数组(取决于表示它的 JSON)。

我认为JSON可以表示的数据结构类别就是:“数据结构”。例如,您可以用 JSON 表示二叉树,甚至可以表示列表和映射;这些本身就是特定的数据结构,它们的总称就是“数据结构”。

假设 JSON 只能表示一种特定类型的数据结构(例如,只能表示树),那么我们可以将 JSON 表示的对象类称为“树”。但 JSON 的作用远不止于此;它可以表示不同类型的数据结构,这就是为什么最好说“我这里有这个 JSON,它表示某某数据结构”。

我想如果你真的把它归结为一个数据结构,它要么是序列,要么是包含名称-值对的结构,其中值可以是基元 (ints, 字符串浮点布尔null未定义)或名称-值对或序列。

再想一想,询问可以用 JSON 表示的数据结构的类名称就像询问可以用 XML 表示的数据结构的类名称一样。两者都是抽象符号,可以具体化为实际对象。

TL; DR; 只需将其称为对象,或者使用其实际的数据结构名称即可。就像说“XML 对象”一样。 XML 表示的结构类没有通用名称。 XML 可以表示一个对象,就像 JSON 可以表示一个对象一样。

JSON is simply a notation that happens to easily translate to Javascript objects. When JSON is reified in Javascript (evaluated), it turns into a Javascript object/associative array (depending on the JSON representing it).

I think the class of data structures that can be represented by JSON are just that: "data structures". For example, you could represent binary trees in JSON, or even lists and maps; these are specific data-structures in their own right, and the overall term for them is just "data structure".

Assuming that JSON could only represent one specific type of data structure (for example, only trees), then we could call the class of objects represented by JSON as just "trees". But JSON does more than that; it can represent different kinds of data structures, which is why it's probably just best to say "I have this JSON here and it represents the so-and-so data-structure".

I guess if you really boil it down, JSON represents a data-structure that is either a sequence or a structure that contains name-value pairs, where the values can be primitives (ints, strings, floats, booleans, nulls, undefineds), or name-value pairs or sequences.

Thinking about it a bit more, asking for the name of the class of data structure that could be represented by JSON is like asking for the name of the class of data structures that could be represented by XML. Both are abstract notations that can be reified into actual objects.

TL; DR; Just call it an object, or by its actual data-structure name. It's just like saying "XML Object". There's no general name for the class of structures represented by XML. XML can represent an object, just like JSON can represent an object.

旧瑾黎汐 2024-12-08 13:19:44

您可以将它们称为“JSON 兼容”或“JSON 可序列化”。

You could call them "JSON-compatible" or "JSON-serializable" maybe.

雨的味道风的声音 2024-12-08 13:19:44

我认为这个问题有点领先,因为如果您覆盖对象的序列化,任何对象都可以用 JSON 表示。

现在,如果您的意思是,哪些对象可以本机表示为 JSON,这取决于您的语言和环境。

I think the question is a little leading since any object could be represented in JSON if you overrode the serialization on the object.

Now if you mean, what objects could natively be represented as JSON, that depends on your language and environment.

永不分离 2024-12-08 13:19:44

有 JSON 对象吗?没有。它不采用它被序列化到的对象类型吗? 如上所述

如果 JSON 是一种数据交换格式,并且 JSON 格式的结果文件遵循规范,那么它不会跟踪您有一个项目数组或列表,而不是对象吗?

Is there a JSON object? Nope. Doesn't it take on the object type that it is serialized to? As above

If JSON is a data interchange format and the resulting files in JSON format follow the specification, doesn't it track that you have an array of or a list of items, not objects?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文