您使用哪个词来描述类似 JSON 的对象?

发布于 2024-08-06 11:25:54 字数 226 浏览 6 评论 0原文

我有一个命名问题。

如果我从某个 JSON 中读取对象 x,我可以调用我的变量 xJson(或某些变体)。然而,有时数据可能来自许多不同的源,其中 JSON 并不特殊(例如 XMLRPC,以编程方式从映射、列表和基元...等构建)。

在这种情况下,变量的好名称是什么?到目前为止,我想出的最好的方法是“DynamicData”之类的东西,在某些情况下还可以,但有点长,对于不熟悉该约定的人来说可能不太清楚。

I have a naming issue.

If I read an object x from some JSON I can call my variable xJson (or some variation). However sometimes it is possible that the data could have come from a number of different sources amongst which JSON is not special (e.g. XMLRPC, programmatically constructed from Maps,Lists & primitives ... etc).

In this situation what is a good name for the variable? The best I have come up with so far is something like 'DynamicData', which is ok in some situations, but is a bit long and not probably not very clear to people unfamiliar with the convention.

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

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

发布评论

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

评论(3

半衬遮猫 2024-08-13 11:25:54

序列化数据?

SerializedData?

╭⌒浅淡时光〆 2024-08-13 11:25:54

无论使用什么序列化格式,哈希值和数据列表的分层集合通常称为文档。另一个有用的描述可能是有效负载正文,即用于传输的消息正文或写入键/值存储的值字符串。

我自己倾向于将对象层次结构称为“文档”,将序列化格式称为“文档”。因此,RequestDocument 被解析为 RequestDoc,并且在进一步识别后,它可能会变成 OrderDoc 或 CustomerUpdateDoc 等。 InvoiceDoc 可能通常被称为 ResponseDoc,最终序列化为 ResponseDocument。

较长的形式很尴尬,但这种序列化字符串通常是短暂的,并且无论如何都会在代码中本地化。

A hierarchical collection of hashes and lists of data is often referred to as a document no matter what serialization format is used. Another useful description might be payload or body in the sense of a message body for transmission or a value string written to a key/value store.

I tend to call the object hierarchy a "doc" myself, and the serialized format a "document." Thus a RequestDocument is parsed into a RequestDoc, and upon further identification it might become an OrderDoc, or a CustomerUpdateDoc, etc. An InvoiceDoc might become known generically as a ResponseDoc eventually serialized to a ResponseDocument.

The longer form is awkward, but such serialized strings are typically short-lived and localized in the code anyway.

国产ˉ祖宗 2024-08-13 11:25:54

如果您的数据是模型,请以其代表的模型命名。例如,根据内容的目的而不是内容的格式来命名。因此,如果它是客户信息列表,请将其命名为“customers”或“customerModel”或类似名称。

如果您不知道内容是什么,那么名称并不重要,除非您想区分格式。 “responseData”、“jsonResponse”等...

并且“DynamicData”不是一个长名称,除非绝对没有关于数据的描述性内容。 “数据”可能就很好。

If your data is the model, name it after the model it's representing. e.g., name it after the purpose of the contents, not the format of the contents. So if it's a list of customer information, name it "customers", or "customerModel", or something like that.

If you don't know what the contents are, the name isn't important, unless you want to differentiate the format. "responseData", "jsonResponse", etc...

And "DynamicData" isn't a long name, unless there is absolutely nothing descriptive to be said about the data. "data" might be just fine.

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