“JSON 对象”应该是什么?称为?
每当这里有人说“我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
JSON 只是一种可以轻松转换为 Javascript 对象的表示法。当 JSON 在 Javascript 中具体化(评估)时,它会变成 Javascript 对象/关联数组(取决于表示它的 JSON)。
我认为JSON可以表示的数据结构类别就是:“数据结构”。例如,您可以用 JSON 表示二叉树,甚至可以表示列表和映射;这些本身就是特定的数据结构,它们的总称就是“数据结构”。
假设 JSON 只能表示一种特定类型的数据结构(例如,只能表示树),那么我们可以将 JSON 表示的对象类称为“树”。但 JSON 的作用远不止于此;它可以表示不同类型的数据结构,这就是为什么最好说“我这里有这个 JSON,它表示某某数据结构”。
我想如果你真的把它归结为一个数据结构,它要么是序列,要么是包含名称-值对的结构,其中值可以是基元 (
int
s,字符串
、浮点
、布尔
、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 (
int
s,string
s,float
s,boolean
s,null
s,undefined
s), 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.
您可以将它们称为“JSON 兼容”或“JSON 可序列化”。
You could call them "JSON-compatible" or "JSON-serializable" maybe.
我认为这个问题有点领先,因为如果您覆盖对象的序列化,任何对象都可以用 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.
有 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?