javascript JSON 中的命名空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3777513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Namespaces in JSON
提问by Jerome
Is there such a thing as JSON namespaces, just like XML namespaces? Has anyone created a spec or libraries for this? Is this a good or a terrible idea?
是否有 JSON 命名空间之类的东西,就像 XML 命名空间一样?有没有人为此创建了规范或库?这是一个好主意还是一个糟糕的主意?
I want to make a data spec that can be represented in XML as well as JSON. However I also need the namespace concept, that the data can be extended by annotations in different vocabularies.
我想制作一个可以用 XML 和 JSON 表示的数据规范。但是,我还需要命名空间概念,即可以通过不同词汇表中的注释来扩展数据。
To be more specific, this is about representing events. My schema will describe the event in basic terms (time and location), though if you think about it, events can be annotated with different information e.g. attendees or image URLs which I don't want to specify in my schema.
更具体地说,这是关于表示事件。我的架构将以基本术语(时间和地点)描述事件,但如果您考虑一下,事件可以使用不同的信息进行注释,例如我不想在我的架构中指定的参与者或图像 URL。
回答by redben
回答by Russ Clarke
JSON Schema might be the right thing for this:
JSON Schema 可能是正确的做法:
Althought I don't know how well it's implemented.
虽然我不知道它的实施情况。
回答by Balint Bako
This is quite an old thread, but there are JSON prefixes, which are almost like namespaces. If you are using Java server-side with Jettison, you can easily meet them.
这是一个相当古老的线程,但有 JSON 前缀,几乎就像命名空间。如果您将 Java 服务器端与Jettison 结合使用,则可以轻松满足它们。

