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


当前回答

虽然有些分析者支持C++式的评论,但我使用的是JsonCpp 专案在这些例子中,有这样一个例子:

// Configuration options
{
    // Default encoding for text
    "encoding" : "UTF-8",

    // Plug-ins loaded at start-up
    "plug-ins" : [
        "python",
        "c++",
        "ruby"
        ],

    // Tab indent size
    "indent" : { "length" : 3, "use_space": true }
}

jsonlint (jsonlint)无法验证这一点。 因此, 批注是解析器特定的扩展名, 而不是标准扩展名 。

另一个解析器是杰森5.

JSON 替代 JSON 的替代方案汤加.

另一种替代办法是:jjsonc 喷气管.

最新版本的最新版本nlohmann/json(日元)可选择支持忽略对解析的评论 。

其他回答

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

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

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

{
  key: "value" // Comment
}

您也可以从#通过设定:

mapper.configure(Feature.ALLOW_YAML_COMMENTS, true);

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

您可以使用 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 Schema是目前提议的因特网规格草案,除了文件以外,还可以使用这一规格来验证你的JSON数据。

示例:

{
  "description": "A person",
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "age": {
      "type": "integer",
      "maximum": 125
    }
  }
}

您可以使用以下工具提供文档:描述说明说明说明说明说明说明schema 属性 。

特意将JSON的评论删除。

我删除了JSON的评论,因为我看到有人利用他们来维持分解指令,这种做法会破坏互操作性。 我知道,缺乏评论会让一些人感到悲哀,但不应该。

假设您正在使用 JSON 保存配置文件, 您想要对此进行注释 。 请继续插入您想要的所有评论 。 然后通过 JSMIN 管道将其传送给您的 JSON 分析员 。

资料来源:Douglas Crockford在G+上的公开声明

json speces 不支持评论, 但是您可以用键来写评论来解决这个问题, 像这样 。

{
  "// my own comment goes here":"",
  "key1":"value 1",

  "// another comment goes here":"",
  "key 2": "value 2 here"
}

我们使用评论文本作为关键, 以确保它们( 几乎) 是独一无二的, 它们不会打破任何解析器。 如果有些评论不是独一无二的, 请在结尾处添加随机数字 。

如果您需要分析任何处理中的评论, 比如剥除这些评论, 您可以用文字填充注释值, 表示它是一个注释 , 比如 :

   {
  "// my own comment goes here" : "_comment",
  "key1":"value 1",

  "// another comment goes here" : "_comment",
  "key 2": "value 2 here"
} 
  

以此方式, 分析者可以找到所有的评论并处理它们 。