我能否在以下发言中发表一些意见?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的简短评论,它允许你在JSON的文件中使用评论!”

{
    // Rainbows
    "unicorn": /* ❤ */ "cake"
}

其他回答

您可以使用JSON-LD (JSON-LD)schema.org 注释用于正确写入备注:

{
    "https://schema.org/comment": "this is a comment"
}

您可以使用 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 字符串, 将会被某个程序读取, 使用 C 或 C++ 样式之前要删除 C 或 C+ 样式的注释会有多困难 ?

答复:这将是一个班轮。 如果您这样做, JSON 文件可以用作配置文件 。

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