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

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

问题描述

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

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

推荐答案

我不相信你可以有实际的评论。

I don't believe you can have an actual comment. The JSON should all be data, 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 would 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天全站免登陆