我可以在json文件里使用注释吗? 如果是的话,怎么写?
当前回答
它取决于您的 json 库。json.net 支持 javascamps 风格的评论,/ * 逗号 * / 。
见另一个堆叠溢出的问题。
其他回答
因此我将调试信息放入 http 网站页眉, 以避免打破客户端:
header("My-Json-Comment: Yes, I know it's a workaround ;-) ");
调
正如许多答案已经指出的,Json在本地没有评论。当然,有时你还是想要评论。对python来说,两种方法就是评论json(和//仅对python 2)或json_tricks(或//对python 2和python 3),这有其他几个特点。免责声明:我做了json_tricks。
这是我在Google Firebbase文档中找到的东西, 可以让你在json中发表评论:
{
"//": "Some browsers will use this to enable push notifications.",
"//": "It is the same for all projects, this is not your project's sender ID",
"gcm_sender_id": "1234567890"
}
我真的很喜欢 @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"
}
}
考虑使用 aml 。 它几乎是 json 的超级集( 几乎所有有效的json 都是有效的 aml ) , 它允许评论 。
推荐文章
- 在VS Code中禁用“Comments are not allowed In JSON”错误
- 如何在Kotlin解析JSON ?
- JSON文件的蒙古导入
- 如何用jQuery / JavaScript解析JSON数据?
- jQuery在请求体中发布有效的json
- 将JSON显示为HTML
- Swift:理解// MARK
- 在JSON键名中哪些字符是有效的/无效的?
- 如何JSON序列化集?
- 如何检查JSON键是否存在?
- 在构建中编写注释的语法是什么?gradle文件?
- 将对象序列化为JSON
- node.js TypeError:路径必须是绝对路径或指定根路径到res.sendFile[解析JSON失败]
- Python json。loads显示ValueError:额外数据
- JSON省略了Infinity和NaN;JSON在ECMAScript中的状态?