我能否在以下发言中发表一些意见?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并不支持本地的评论, 但您可以自己制作解码器或至少预处理器来删除评论, 这完全没问题(只要您只是忽略评论, 不使用它们来指导您的应用程序如何处理 JSON 数据 ) 。
JSON没有评论。 JSON 编码器必须输入输出评论。 JSON 编码器可能接受和忽略评论。
评论绝不应被用来传递任何有意义的信息。这就是JSON的目的。
其他回答
有一个很好的解决办法(骗局),这是有效的JSON(JSON),但并非在所有情况下都有效,只需两次(或两次以上)设定相同的键。 例如:
{
"param" : "This is the comment place",
"param" : "This is value place",
}
所以JSON会理解这一点:
{
"param" : "This is value place",
}
JSON的理念是提供各种应用之间的简单数据交换,这些应用通常是基于网络的,语言是JavaScript。
但是,它实际上不允许这样的评论, 但是,作为数据中的名字/价值对之一通过评论肯定行得通, 尽管数据显然需要被忽略或由解析代码具体处理。
尽管如此,但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里加入评论,链接链接如果JSON应该有评论的话,为什么不将其标准化,让JSON专家来做这项工作?我不同意逻辑,但不幸的是,这是标准。使用由其他人建议的YAML解决方案是好的,但它需要依赖图书馆。
如果您想要删除批注, 但不想有库依赖性, 这里是一个双线解决方案, 适用于 C++ 风格的批注, 但可以调整为其它 :
var comments = new RegExp("//.*", 'mg');
data = JSON.parse(fs.readFileSync(sample_file, 'utf8').replace(comments, ''));
请注意,只有在您可以确信JSON数据不含评论发起人(例如('/'))的情况下,才能使用这一解决办法。
实现 JSON 解析、 解开评论和不增加图书馆的另一种方式是用 JavaScript 解释器来评价 JSON 。 当然,这个方法的告诫是, 您只想要评估未污染的数据( 不可信用户- 输入 ) 。 这是在 Node.js 中的一个例子 -- 另一个警告是, 以下示例只读过一次数据, 然后它会被缓存 :
data = require(fs.realpathSync(doctree_fp));
写作时缩略语.json支持意见。
例如(样本样本样本瑞微软)
{
"Logging": {
"LogLevel": { // All providers, LogLevel applies to all the enabled providers.
"Default": "Error", // Default logging, Error and higher.
"Microsoft": "Warning" // All Microsoft* categories, Warning and higher.
},
"Debug": { // Debug provider.
"LogLevel": {
"Default": "Information", // Overrides preceding LogLevel:Default setting.
"Microsoft.Hosting": "Trace" // Debug:Microsoft.Hosting category.
}
},
"EventSource": { // EventSource provider
"LogLevel": {
"Default": "Warning" // All categories of EventSource provider.
}
}
}
}
推荐文章
- 查询JSON类型内的数组元素
- 将JSON字符串转换为HashMap
- 将JsonNode转换为POJO
- Json_encode()转义正斜杠
- 如何写一个JSON文件在c# ?
- 在序列化和反序列化期间JSON属性的不同名称
- 为什么PHP的json_encode函数转换UTF-8字符串为十六进制实体?
- Ajax会调用什么样的响应,比如'for (;;);{json data}的意思?
- 在JavaScript中将JSON字符串解析为特定对象原型
- 使用Jackson将JSON字符串转换为漂亮的打印JSON输出
- jQuery。由于转义了JSON中的单引号,parseJSON抛出“无效JSON”错误
- 用c#解析JSON
- 如何合并2 JSON对象从2个文件使用jq?
- 在VS Code中禁用“Comments are not allowed In JSON”错误
- 如何在Kotlin解析JSON ?