我能否在以下发言中发表一些意见?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-LD (JSON-LD)schema.org 注释用于正确写入备注:

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

其他回答

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

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

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

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

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

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

Enter image description here

如果您正在使用 NewtonSoft.Json 库和 ASP.NET 来读取/删除您在 JSON 内容中可以使用 :

/"名字": "字符串"

//“ id” : 整数

* 这是

注释示例 */

PS :单行评论仅以6+版本的牛顿软 Json 支持。

给那些无法思考的人的附加说明:我在一个 ASP.NET 网络应用程序中使用了用于基本设置的 JSON 格式。 我读了文件, 将其转换成设置对象, 与 Newtonoft 库一起使用, 必要时使用 。

我更喜欢在JSON档案中写关于每个设置的评论, 我真的不在乎JSON格式的完整性, 只要我使用的图书馆可以使用。

我认为这比创建单独的“ 设置. README” 文件并解释其中的设置更容易使用/ 理解” 。

如果你对这种用法有问题, 对不起, 精灵从灯里出来了。 人们会发现JSON格式的其他用法, 您对此无能为力 。

是的,你可以,但你的分析 可能会失败(没有标准)

要分析这些注释,您应该删除这些注释,或者通过手写,或者使用正则表达式:

它取代任何评论,例如:

/****
 * Hey
 */

/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/

它取代任何评论,例如:

// Hey

/\/\/.*/

在JavaScript, 你可以做这样的事情:

jsonString = jsonString.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/, "").replace(/\/\/.*/,"")
var object = JSON.parse(jsonString);

您可以使用 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 }

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