我能否在以下发言中发表一些意见?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如果有,如何处理?
当前回答
是的,你可以,但你的分析 可能会失败(没有标准)
要分析这些注释,您应该删除这些注释,或者通过手写,或者使用正则表达式:
它取代任何评论,例如:
/****
* Hey
*/
/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/
它取代任何评论,例如:
// Hey
/\/\/.*/
在JavaScript, 你可以做这样的事情:
jsonString = jsonString.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/, "").replace(/\/\/.*/,"")
var object = JSON.parse(jsonString);
其他回答
写作时缩略语.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.
}
}
}
}
您可以通过正则表达式使用简单的预处理。例如,以下函数将解码在 PHP 中评论 JSON:
function json_decode_commented ($data, $objectsAsArrays = false, $maxDepth = 512, $opts = 0) {
$data = preg_replace('~
(" (?:[^"\\\\] | \\\\\\\\ | \\\\")*+ ") | \# [^\v]*+ | // [^\v]*+ | /\* .*? \*/
~xs', '$1', $data);
return json_decode($data, $objectsAsArrays, $maxDepth, $opts);
}
它支持所有PHP风格的评论: / *, #, / /。 字符串的字句保留不变 。
这是我在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"
}
你,你,你能够有评论意见的年份贾索普我只是花了一个小时 试图让程序与例如,Highcharts的这个例子.
如果你跟着链接,你会看到
?(/* AAPL historical OHLC data from the Google Finance API */
[
/* May 2006 */
[1147651200000,67.79],
[1147737600000,64.98],
...
[1368057600000,456.77],
[1368144000000,452.97]
]);
因为我在本地文件夹里也有类似的文件 没有问题同源政策所以我决定使用纯JSON... 当然,$.getJSON
由于这些评论而无声无息地失败。
最后,我刚刚向上述地址发送了 HTTP 手动请求, 并意识到内容类型是text/javascript
自此, JSONP 返回纯 JavaScript 。允许但我的应用程序返回了内容类型application/json
所以我不得不去掉那些评论
纯粹的答案是否 无.
但有些编辑和平台利用变通办法向JSON提供评论。
1今天,大多数编辑都有内在的选择和扩展,以补充对JSON文件的评论。 (例如: - VS 代码还有一个带有评论的JSON。(jsonc) mode
《VS法典》也有很好的展期)
2一些平台为补充评论(简简json)提供了内在途径。 (例如:- 在消防基地,我可以评论firebase.json
暂时没有问题。
{
"hosting": {
"headers": [
/*{
"source": "*.html",
"headers": [
{
"key": "Content-Security-Policy",
"value": "default-src 'self' ..."
}
]
},*/
]
}
}
3。在您自己的 JSON 解析方法中,您可以设置一个预定义的密钥名称作为注释。
包括:-
{
"comment" : "This is a comment",
"//" : "This also comment",
"name" : "This is a real value"
}
推荐文章
- 查询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 ?