Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

json - 可以在JSON中使用注释吗?(Can comments be used in JSON?)

Can I use comments inside a JSON file?

(我可以在JSON文件中使用注释吗?)

If so, how?

(如果是这样,怎么办?)

  ask by Michael Gundlach translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No.

(没有。)

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

(JSON应该都是数据,如果包含注释,那么它也将是数据。)

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

(您可能有一个名为"_comment" (或其他名称)的指定数据元素,使用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.

(在生成/接收JSON的过程中添加注释可能会更好,因为它们应该事先知道什么是JSON数据,或者至少知道其结构。)

But if you decided to:

(但是,如果您决定:)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...