我能否在以下发言中发表一些意见?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 规格不支持评论,// or /* */样式。

但一些JSON分析图书馆和国际开发实体支持它们。

类似 :

  1. 杰森5
  2. 视觉工作室代码
  3. Commentjson 评论

其他回答

正如许多答复已经指出的,JSON在本地没有评论。当然,有时你还是想要评论。Python 符号,两个方法commentjson (#//仅用于 Python 2 的)或json_tricks (#//Python 2 和 Python 3 的 Python 2 和 Python 3, 具有其他几个特点。json_tricks.

*.json文件通常用作配置文件或静态数据,因此需要评论 * NetBeans等编辑在 *.json中接受评论。

问题在于将内容解析到对象上。 解决方案是总是应用清洁功能( 服务器或客户端 ) 。

普 普 普 尔

 $rgx_arr = ["/\/\/[^\n]*/sim", "/\/\*.*?\*\//sim", "/[\n\r\t]/sim"];
 $valid_json_str = \preg_replace($rgx_arr, '', file_get_contents(path . 'a_file.json'));

贾瓦史克里普特

valid_json_str = json_str.replace(/\/\/[^\n]*/gim,'').replace(/\/\*.*?\*\//gim,'')

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

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

虽然有些分析者支持C++式的评论,但我使用的是JsonCpp 专案在这些例子中,有这样一个例子:

// Configuration options
{
    // Default encoding for text
    "encoding" : "UTF-8",

    // Plug-ins loaded at start-up
    "plug-ins" : [
        "python",
        "c++",
        "ruby"
        ],

    // Tab indent size
    "indent" : { "length" : 3, "use_space": true }
}

jsonlint (jsonlint)无法验证这一点。 因此, 批注是解析器特定的扩展名, 而不是标准扩展名 。

另一个解析器是杰森5.

JSON 替代 JSON 的替代方案汤加.

另一种替代办法是:jjsonc 喷气管.

最新版本的最新版本nlohmann/json(日元)可选择支持忽略对解析的评论 。

纯粹的答案是否 无.

但有些编辑和平台利用变通办法向JSON提供评论。

1今天,大多数编辑都有内在的选择和扩展,以补充对JSON文件的评论。 (例如: - VS 代码还有一个带有评论的JSON。(jsonc) mode《VS法典》也有很好的展期)

VsCode 中激活 jsonc 模式的链接

2一些平台为补充评论(简简json)提供了内在途径。 (例如:- 在消防基地,我可以评论firebase.json暂时没有问题。

    {
    "hosting": {
        "headers": [
            /*{
              "source": "*.html",
              "headers": [
                {
                  "key": "Content-Security-Policy",
                  "value": "default-src 'self' ..."
                }
              ]
            },*/
        ]
      }
    }

3。在您自己的 JSON 解析方法中,您可以设置一个预定义的密钥名称作为注释。

包括:-

     {
        "comment" : "This is a comment",
        "//" :  "This also comment",
        "name" : "This is a real value"
     }