我能否在以下发言中发表一些意见?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-LD (JSON-LD)和schema.org 注释用于正确写入备注:
{
"https://schema.org/comment": "this is a comment"
}
其他回答
正如许多答复已经指出的,JSON在本地没有评论。当然,有时你还是想要评论。Python 符号,两个方法commentjson
(#
和//
仅用于 Python 2 的)或json_tricks
(#
或//
Python 2 和 Python 3 的 Python 2 和 Python 3, 具有其他几个特点。json_tricks
.
将JSON项目切成部分... ...我添加了"不切实际的评论"的行:
{
"#############################" : "Part1",
"data1" : "value1",
"data2" : "value2",
"#############################" : "Part2",
"data4" : "value3",
"data3" : "value4"
}
是的,你可以发表意见,但我建议不提出上述任何理由。
我做了一些调查, 我发现所有JSON需要的方法 使用JSON.parse
方法。所以我找到了一个解决方案: 我们可以在JSON.parse周围取代或修补猴子。
注:仅用节点js测试;-)
var oldParse = JSON.parse;
JSON.parse = parse;
function parse(json){
json = json.replace(/\/\*.+\*\//, function(comment){
console.log("comment:", comment);
return "";
});
return oldParse(json)
}
JSON 文件 :
{
"test": 1
/* Hello, babe */
}
您可以使用 JSON 及其注释, 如果您把它作为文本文件载入, 然后删除注释 。
例如,您可以使用折分用于此目的的库。 下面是一个完整的例子 。
输入 JSON (文件输入.js) :
/*
* multi-line comments
**/
{
"value": 123 // one-line comment
}
测试应用 :
var decomment = require('decomment');
var fs = require('fs');
fs.readFile('input.js', 'utf8', function (err, data) {
if (err) {
console.log(err);
} else {
var text = decomment(data); // removing comments
var json = JSON.parse(text); // parsing JSON
console.log(json);
}
});
产出:
{ value: 123 }
另见:硫酸脱硫, - - 贬 - 贬 - 贬 - 贬 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音
我们正在使用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'}
推荐文章
- 查询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 ?