我能否在以下发言中发表一些意见?Json Json (Json Json) (Json Json Json) (Json Json) Json Json (Json Json) Json (Json) Json (Json) Json (Json) Json (Json) Json (Json) Json (Json) Json(Json) Json (Json) Json (Json) Json(Json) Json (Json) Json如果有,如何处理?


当前回答

使用杰森5您可以包含注释。


JSON5建议延长JSON5的有效期这样做的方式是直接从ECMAScript 5中增加一些最低限度的语法特征。

其他回答

您当然可以对 JSON 进行评论。 要阅读 JavaScript 的JSON 注释文件, 您可以在解析前删除评论( 参见下面的代码 ) 。 我相信这个代码可以改进, 但对于使用常规表达式的人来说很容易理解 。

我用评论的JSON文件来为我的合成反射系统指定神经元形状。我还用评论的JSON来储存一个运行中的神经元系统的中间状态。非常方便有评论。不要听那些告诉你他们是个坏主意的动作。

fetch(filename).then(function(response) {
    return response.text();
}).then(function(commented) {
    return commented.
        replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1').
        replace(/\r/,"\n").
        replace(/\n[\n]+/,"\n");
}).then(function(clean) {
    return JSON.parse(clean);
}).then(function(json) {
    // Do what you want with the JSON object.
});

你不行,至少这就是我的经验json.org.

JSON的语法在那一页上被视觉化了, 没有任何关于评论的注释。

虽然JSON不支持评论,杰森确实如此。

使用“.jsonc”扩展名命名您的文件并使用jjsonc 喷气管解剖师
如果回答为时已晚, 抱歉 。

jsonWithComments.jsonc

示例:

{
    // This is a comment!
    "something": "idk"

}

如果情况不明,我认为机器人是怪异的。请在投票之前先试一下,因为这个问题没有帮助。

我们正在使用strip-json-comments支持我们的项目。 它支持一些东西,比如:

/*
 * Description 
*/
{
    // rainbows
    "unicorn": /* ❤ */ "cake"
}

简简npm install --save strip-json-comments安装和使用它如下:

var strip_json_comments = require('strip-json-comments')
var json = '{/*rainbows*/"unicorn":"cake"}';
JSON.parse(strip_json_comments(json));
//=> {unicorn: 'cake'}

没有 No.

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