我能否在以下发言中发表一些意见?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 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"
} 
  

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

其他回答

我只是为配置文件才看到这个 我不想用XML 数字或“ini”格式(没有等级,没有真正的标准,等等)或Java“Propertys”格式(如.ini)。

JSON可以做他们所能做的一切,但是它不那么多动词,更易为人读——在许多语言中,剖析器很容易,而且无处不在。它只是一棵数据树。但它只是一棵数据树。但是,用“默认”的配置等文件来记录“默认”的配置和类似内容往往是必要的。配置从来不是“完整的文档 ” , 而是需要时可以读取的保存数据树。

我想用得着"#": "comment"为了"活人"JSON

在JSON的输出之前,我需要将评论用于调试目的。所以我把调试信息放进HTTP 信头为了避免客户被打破:

header("My-Json-Comment: Yes, I know it's a workaround ;-) ");

Enter image description here

您当然可以对 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.
});

Dojo工具包 JavaScript工具包(至少是1.4版)允许您在 JSON 中加入评论。/* */Dojo 工具包使用JSONdojo.xhrGet()拨打。

其他JavaScript工具箱也可能同样发挥作用。

在选择最后选择之前先试验其他数据结构(甚至数据清单)时,这样做会有帮助。

叹气,为什么不只添加字段,例如:

{
    "note1" : "This demonstrates the provision of annotations within a JSON file",
    "field1" : 12,
    "field2" : "some text",

    "note2" : "Add more annotations as necessary"
}

只要确保你的"笔记本"名字 不要与任何真正的田地冲突。