如何在 .json 文件中添加注释

hua*_*990 8 javascript json comments

考虑:

{
    "one": {
        "one1":"one11",
        "System Name":"ssss"
    },
    "two2": [
        ["two20", "two200"]
    ]
}
Run Code Online (Sandbox Code Playgroud)

如果我使用'/* comments */'或//comments,我无法获取JSON数据。

但我的数据太多了,我必须添加评论。

还有其他方法吗?

小智 3

,注释不是JSON RFC 7159的一部分。然而,有一些 JSON 解析器支持 C++ 风格的注释:

{
  "img":{ "width": 320, "height": 240 } // Picture details
}
Run Code Online (Sandbox Code Playgroud)

请参阅JSON++

所以答案取决于您要如何处理 JSON。JavaScript-JSON 解析器 ( JSON.parse()) 不支持此功能。