我可以在json文件里使用注释吗? 如果是的话,怎么写?


当前回答

至少这是我在Json. org的一眼 所经历的

json的语法在那一页上被视觉化了。

其他回答

您应该撰写json schema。json schema目前是一份拟议互联网规格草案。除文档外,该schema还可以用于验证您的json数据 。

例如:

{
  "description": "A person",
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "age": {
      "type": "integer",
      "maximum": 125
    }
  }
}

您可以使用描述 schema 属性提供文档。

*.json文件通常用作配置文件或静态数据,因此需要评论 * 一些像Netbeans这样的编辑在 *.json中接受评论。

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

php /p

 $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的语法在那一页上被视觉化了。

考虑使用 aml 。 它几乎是 json 的超级集( 几乎所有有效的json 都是有效的 aml ) , 它允许评论 。

您可以使用 json-ld 和 schema.org 批注类型来正确写备注:

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