小编典典

JSON 中可以使用注释吗?

json

我可以在 JSON 文件中使用注释吗?如果是这样,如何?


阅读 416

收藏
2021-12-30

共1个答案

小编典典

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

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

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

但如果你决定:

{
   "_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"
            }
         }
      }
   }
}
2021-12-30