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


当前回答

我喜欢 @eli ' s 方法, 超过 30 个答案, 但没有人提到列表( array) 。 所以使用 @eli ' s 方法, 我们可以做一些类似的事情:

"part_of_speech": {
  "__comment": [
    "@param {String} type - the following types can be used: ",
      "NOUN, VERB, ADVERB, ADJECTIVE, PRONOUN, PREPOSITION",
      "CONJUNCTION, INTERJECTION, NUMERAL, PARTICLE, PHRASE",
    "@param {String} type_free_form - is optional, can be empty string",
    "@param {String} description - is optional, can be empty string",
    "@param {String} source - is optional, can be empty string"
  ],
  "type": "NOUN",
  "type_free_form": "noun",
  "description": "",
  "source": "https://google.com",
  "noun_class": {
    "__comment": [
      "@param {String} noun_class - the following types can be used: ",
        "1_class, 2_class, 3_class, 4_class, 5_class, 6_class"
    ],
    "noun_class": "4_class"
  }
}

其他回答

我们正在使用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'}

如果您的上下文是 NOde.js 配置, 您可以考虑 JavaScript 通过module.exports作为JSON的替代:

module.exports = {
    "key": "value",

    // And with comments!
    "key2": "value2"
};

缩略require语法将保持不变 。 作为 JavaScript, 文件扩展名应该是.js.

是 是新的标准,杰森5在许多 C+++ 样式批注中允许 C++ 样式批注其它延长:

// A single line comment.

/* A multi-
   line comment. */

JSON5 数据交换格式(JSON5)是JSON的超级组合,旨在减轻JSON的某些限制。它完全向后兼容,使用它可能比写自定义的非标准分析器、为现有分析器打开非标准功能或使用像字符串字段等各种黑客来评论要好一些。或者,如果正在使用的分析器支持的话,简单同意我们正在使用 JSON 5子集,即 JSON 和 C++ 样式注释。它比我们把JSON标准为我们所认为的合适.

已经存在npm 软件包包, Python 软件包包, Java 软件包C 图书馆库我认为没有理由坚持“官方的”JSON限制。

我认为,将JSON的评论从JSON删除的原因与在爪哇清除操作员超载的原因相同:可能会被错误地使用,但一些显然合理的使用案例却被忽视。对于操作员超载,它是矩阵代数和复杂数字。 对于JSON的评论,它是一个配置文件和其他文件,可以由人类而不是仅仅由分析员来撰写、编辑或阅读。

这是我在Google 火底文件允许你对JSON发表评论:

{
  "//": "Some browsers will use this to enable push notifications.",
  "//": "It is the same for all projects, this is not your project's sender ID",
  "gcm_sender_id": "1234567890"
}

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

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