我能否在以下发言中发表一些意见?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如果有,如何处理?
当前回答
虽然有些分析者支持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兼容,
其中一个显著的例子是:“Hashcorp语言”(HCL)” (HCL)由那些制造流浪者、包装者、领事和保险库的人共同撰写。
json speces 不支持评论, 但是您可以用键来写评论来解决这个问题, 像这样 。
{
"// my own comment goes here":"",
"key1":"value 1",
"// another comment goes here":"",
"key 2": "value 2 here"
}
我们使用评论文本作为关键, 以确保它们( 几乎) 是独一无二的, 它们不会打破任何解析器。 如果有些评论不是独一无二的, 请在结尾处添加随机数字 。
如果您需要分析任何处理中的评论, 比如剥除这些评论, 您可以用文字填充注释值, 表示它是一个注释 , 比如 :
{
"// my own comment goes here" : "_comment",
"key1":"value 1",
"// another comment goes here" : "_comment",
"key 2": "value 2 here"
}
以此方式, 分析者可以找到所有的评论并处理它们 。
我喜欢 @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文件通常用作配置文件或静态数据,因此需要评论 * 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,'')
实际的答案:视觉工作室代码2019年的用户将使用“ jsonc” 扩展名 。
这是切合实际的,因为这是视觉演播室代码所认可的延伸,以表明“JSON与评论”,请在下面的评论中告诉我其他编辑/编辑的情况。
如果视觉演播室代码和其他编辑也会加入当地对JSON5的支持,
(我在张贴前搜索了所有答案,
推荐文章
- 在ASP中设置Access-Control-Allow-OriginNet MVC -最简单的方法
- JWT vs cookie用于基于令牌的身份验证
- JQ:选择多个条件
- 什么是HTTP中的“406-不可接受的响应”?
- 有没有办法注释掉.ASPX页面中的标记?
- ASP。NET Core返回带有状态码的JSON
- 我如何添加环境变量启动。VSCode中的json
- PostgreSQL返回JSON数组的结果集?
- HTTP POST在Java中使用JSON
- 如何指定杰克逊只使用字段-最好是全局
- jQuery为ajax请求返回“parsererror”
- 检查Postgres JSON数组是否包含字符串
- 将bash变量传递给jq
- 在$.ajax()中将数组传递给ajax请求
- 转换JSON字符串到c#对象