JSON 中可以使用注释吗? [英] Can comments be used in JSON?

查看:26
本文介绍了JSON 中可以使用注释吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 JSON 文件中使用注释吗?如果是,怎么办?

Can I use comments inside a JSON file? If so, how?

推荐答案

没有

JSON 只是数据,如果您包含注释,那么它也是数据.

The JSON is data only, and if you include a comment, then it will be data too.

您可以指定一个名为 "_comment"(或其他内容)的数据元素,使用 JSON 数据的应用应该忽略该数据元素.

You could have a designated data element called "_comment" (or something) that should be ignored by apps that use the JSON data.

您可能最好在生成/接收 JSON 的过程中添加注释,因为他们应该提前知道 JSON 数据是什么,或者至少知道它的结构.

You would probably be better having the comment in the processes that generates/receives the JSON, as they are supposed to know what the JSON data will be in advance, or at least the structure of it.

但如果你决定:

{
   "_comment": "comment text goes here...",
   "glossary": {
      "title": "example glossary",
      "GlossDiv": {
         "title": "S",
         "GlossList": {
            "GlossEntry": {
               "ID": "SGML",
               "SortAs": "SGML",
               "GlossTerm": "Standard Generalized Markup Language",
               "Acronym": "SGML",
               "Abbrev": "ISO 8879:1986",
               "GlossDef": {
                  "para": "A meta-markup language, used to create markup languages such as DocBook.",
                  "GlossSeeAlso": ["GML", "XML"]
               },
               "GlossSee": "markup"
            }
         }
      }
   }
}

这篇关于JSON 中可以使用注释吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆