我能否在以下发言中发表一些意见?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如果有,如何处理?


当前回答

写作时缩略语.json支持意见。

例如(样本样本样本瑞微软)

{
  "Logging": {
    "LogLevel": { // All providers, LogLevel applies to all the enabled providers.
      "Default": "Error", // Default logging, Error and higher.
      "Microsoft": "Warning" // All Microsoft* categories, Warning and higher.
    },
    "Debug": { // Debug provider.
      "LogLevel": {
        "Default": "Information", // Overrides preceding LogLevel:Default setting.
        "Microsoft.Hosting": "Trace" // Debug:Microsoft.Hosting category.
      }
    },
    "EventSource": { // EventSource provider
      "LogLevel": {
        "Default": "Warning" // All categories of EventSource provider.
      }
    }
  }
}

其他回答

实际的答案:视觉工作室代码2019年的用户将使用“ jsonc” 扩展名 。

这是切合实际的,因为这是视觉演播室代码所认可的延伸,以表明“JSON与评论”,请在下面的评论中告诉我其他编辑/编辑的情况。

如果视觉演播室代码和其他编辑也会加入当地对JSON5的支持,

(我在张贴前搜索了所有答案,

这取决于你的JSON图书馆Json.NET支持 JavaScript 风格的评论,/* commment */.

见见另一个堆叠溢出问题.

纯粹的答案是否 无.

但有些编辑和平台利用变通办法向JSON提供评论。

1今天,大多数编辑都有内在的选择和扩展,以补充对JSON文件的评论。 (例如: - VS 代码还有一个带有评论的JSON。(jsonc) mode《VS法典》也有很好的展期)

VsCode 中激活 jsonc 模式的链接

2一些平台为补充评论(简简json)提供了内在途径。 (例如:- 在消防基地,我可以评论firebase.json暂时没有问题。

    {
    "hosting": {
        "headers": [
            /*{
              "source": "*.html",
              "headers": [
                {
                  "key": "Content-Security-Policy",
                  "value": "default-src 'self' ..."
                }
              ]
            },*/
        ]
      }
    }

3。在您自己的 JSON 解析方法中,您可以设置一个预定义的密钥名称作为注释。

包括:-

     {
        "comment" : "This is a comment",
        "//" :  "This also comment",
        "name" : "This is a real value"
     }

您可以使用 JSON 及其注释, 如果您把它作为文本文件载入, 然后删除注释 。

例如,您可以使用折分用于此目的的库。 下面是一个完整的例子 。

输入 JSON (文件输入.js) :

/*
* multi-line comments
**/
{
    "value": 123 // one-line comment
}

测试应用 :

var decomment = require('decomment');
var fs = require('fs');

fs.readFile('input.js', 'utf8', function (err, data) {
    if (err) {
        console.log(err);
    } else {
        var text = decomment(data); // removing comments
        var json = JSON.parse(text); // parsing JSON
        console.log(json);
    }
});

产出:

{ value: 123 }

另见:硫酸脱硫, - - 贬 - 贬 - 贬 - 贬 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音

如果您正在使用杰克逊JSON作为您的 JSON 分析者, 那么这就是你如何 允许它 允许评论:

ObjectMapper mapper = new ObjectMapper().configure(Feature.ALLOW_COMMENTS, true);

然后,你可以有这样的评论:

{
  key: "value" // Comment
}

您也可以从#通过设定:

mapper.configure(Feature.ALLOW_YAML_COMMENTS, true);

但总的来说(如前所述),规格不允许作出评论。