我能否在以下发言中发表一些意见?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如果有,如何处理?


当前回答

我喜欢 @eli ' s 方法, 超过 30 个答案, 但没有人提到列表( array) 。 所以使用 @eli ' s 方法, 我们可以做一些类似的事情:

"part_of_speech": {
  "__comment": [
    "@param {String} type - the following types can be used: ",
      "NOUN, VERB, ADVERB, ADJECTIVE, PRONOUN, PREPOSITION",
      "CONJUNCTION, INTERJECTION, NUMERAL, PARTICLE, PHRASE",
    "@param {String} type_free_form - is optional, can be empty string",
    "@param {String} description - is optional, can be empty string",
    "@param {String} source - is optional, can be empty string"
  ],
  "type": "NOUN",
  "type_free_form": "noun",
  "description": "",
  "source": "https://google.com",
  "noun_class": {
    "__comment": [
      "@param {String} noun_class - the following types can be used: ",
        "1_class, 2_class, 3_class, 4_class, 5_class, 6_class"
    ],
    "noun_class": "4_class"
  }
}

其他回答

有一个很好的解决办法(骗局),这是有效的JSON(JSON),但并非在所有情况下都有效,只需两次(或两次以上)设定相同的键。 例如:

{
  "param" : "This is the comment place",
  "param" : "This is value place",
}

所以JSON会理解这一点:

{
  "param" : "This is value place",
}

使用杰森5您可以包含注释。


JSON5建议延长JSON5的有效期这样做的方式是直接从ECMAScript 5中增加一些最低限度的语法特征。

考虑使用雅姆勒它几乎是JSON的超集(几乎所有有效的JSON都是有效的YAML),它允许评论。

*.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,'')

Dojo工具包 JavaScript工具包(至少是1.4版)允许您在 JSON 中加入评论。/* */Dojo 工具包使用JSONdojo.xhrGet()拨打。

其他JavaScript工具箱也可能同样发挥作用。

在选择最后选择之前先试验其他数据结构(甚至数据清单)时,这样做会有帮助。