我能否在以下发言中发表一些意见?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专家来做这项工作?我不同意逻辑,但不幸的是,这是标准。使用由其他人建议的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));
其他回答
虽然有些分析者支持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和JSON需要提出评论。至少可在.NET Core 中提供评论。JSON和牛顿软JSON 工作很顺利
{
// this is a comment for those who is ok with being different
"regular-json": "stuff"...
}
我们正在使用strip-json-comments
支持我们的项目。 它支持一些东西,比如:
/*
* Description
*/
{
// rainbows
"unicorn": /* ❤ */ "cake"
}
简简npm install --save strip-json-comments
安装和使用它如下:
var strip_json_comments = require('strip-json-comments')
var json = '{/*rainbows*/"unicorn":"cake"}';
JSON.parse(strip_json_comments(json));
//=> {unicorn: 'cake'}
这是我在Google 火底文件允许你对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"
}
推荐文章
- 查询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 ?