我能否在以下发言中发表一些意见?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.parse(JSON.minify(my_str));
当我发布时,我得到了一股巨大的反感, 许多人甚至不同意这个想法, 所以我决定写一篇全面的博客文章, 说明为什么JSON认为,它包括JSON创始人的这一引人瞩目的评论:
假设您正在使用 JSON 保存配置文件, 您想要对此进行注释 。 请继续插入您想要的所有评论 。 然后通过 JSMIN 管道将其传送给您的 JSON 分析者 。 - 将它交给您 JSON 分析者 。Douglas Crockford,2012年
希望这样能帮助那些不同意为什么JSON. 最小化 ()可能有用。
其他回答
原为:JSON发明家说:
JSON没有评论。 JSON 编码器必须输入输出评论。 JSON 编码器可能接受和忽略评论。
功用jjq jq包含一个解码器, 它允许“ #” 式的评论, 所以jq 是一种工具, 可以与 JSON 与注释文件一起使用, 只要这些文件被当作“ jq 程序” 处理, 而不是作为 JSON 文件处理 。 例如 :
$ jq -ncf <(echo $'[1, # one\n2 ] # two')
[1,2]
更重要的是,jq可以处理庞大的JSON与评论文件作为程序;这可以用众所周知的JSON文件加以说明:
$ ls -l JEOPARDY_QUESTIONS1.json
-rw-r--r-- 2 xyzzy staff 55554625 May 12 2016 JEOPARDY_QUESTIONS1.json
$ jq -nf JEOPARDY_QUESTIONS1.json | jq length
216930
JSON本身不允许评论。 推理是完全愚蠢的, 因为你可以使用JSON。本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身 本身提出评论,完全排除推理,和在完全没有正当理由的情况下装入解析器数据空间精确同一结果和潜在问题,如:JSON档案,附有评论。
如果您试图在(使用)
//
或/* */
或#
举例说 ) , 那么有些分析师会失败, 因为这严格地说不在JSON 的规格之内。 所以您应该从未这样做。
例如,这里,这里,这里,这里,我的图像处理系统已保存图像标记和一些基本格式化(注释)信息( 在底部) :
{
"Notations": [
{
"anchorX": 333,
"anchorY": 265,
"areaMode": "Ellipse",
"extentX": 356,
"extentY": 294,
"opacity": 0.5,
"text": "Elliptical area on top",
"textX": 333,
"textY": 265,
"title": "Notation 1"
},
{
"anchorX": 87,
"anchorY": 385,
"areaMode": "Rectangle",
"extentX": 109,
"extentY": 412,
"opacity": 0.5,
"text": "Rect area\non bottom",
"textX": 98,
"textY": 385,
"title": "Notation 2"
},
{
"anchorX": 69,
"anchorY": 104,
"areaMode": "Polygon",
"extentX": 102,
"extentY": 136,
"opacity": 0.5,
"pointList": [
{
"i": 0,
"x": 83,
"y": 104
},
{
"i": 1,
"x": 69,
"y": 136
},
{
"i": 2,
"x": 102,
"y": 132
},
{
"i": 3,
"x": 83,
"y": 104
}
],
"text": "Simple polygon",
"textX": 85,
"textY": 104,
"title": "Notation 3"
}
],
"imageXW": 512,
"imageYW": 512,
"imageName": "lena_std.ato",
"tinyDocs": {
"c01": "JSON image notation data:",
"c02": "-------------------------",
"c03": "",
"c04": "This data contains image notations and related area",
"c05": "selection information that provides a means for an",
"c06": "image gallery to display notations with elliptical,",
"c07": "rectangular, polygonal or freehand area indications",
"c08": "over an image displayed to a gallery visitor.",
"c09": "",
"c10": "X and Y positions are all in image space. The image",
"c11": "resolution is given as imageXW and imageYW, which",
"c12": "you use to scale the notation areas to their proper",
"c13": "locations and sizes for your display of the image,",
"c14": "regardless of scale.",
"c15": "",
"c16": "For Ellipses, anchor is the center of the ellipse,",
"c17": "and the extents are the X and Y radii respectively.",
"c18": "",
"c19": "For Rectangles, the anchor is the top left and the",
"c20": "extents are the bottom right.",
"c21": "",
"c22": "For Freehand and Polygon area modes, the pointList",
"c23": "contains a series of numbered XY points. If the area",
"c24": "is closed, the last point will be the same as the",
"c25": "first, so all you have to be concerned with is drawing",
"c26": "lines between the points in the list. Anchor and extent",
"c27": "are set to the top left and bottom right of the indicated",
"c28": "region, and can be used as a simplistic rectangular",
"c29": "detect for the mouse hover position over these types",
"c30": "of areas.",
"c31": "",
"c32": "The textx and texty positions provide basic positioning",
"c33": "information to help you locate the text information",
"c34": "in a reasonable location associated with the area",
"c35": "indication.",
"c36": "",
"c37": "Opacity is a value between 0 and 1, where .5 represents",
"c38": "a 50% opaque backdrop and 1.0 represents a fully opaque",
"c39": "backdrop. Recommendation is that regions be drawn",
"c40": "only if the user hovers the pointer over the image,",
"c41": "and that the text associated with the regions be drawn",
"c42": "only if the user hovers the pointer over the indicated",
"c43": "region."
}
}
你,你,你能够有评论意见的年份贾索普我只是花了一个小时 试图让程序与例如,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项目切成部分... ...我添加了"不切实际的评论"的行:
{
"#############################" : "Part1",
"data1" : "value1",
"data2" : "value2",
"#############################" : "Part2",
"data4" : "value3",
"data3" : "value4"
}
有一个很好的解决办法(骗局),这是有效的JSON(JSON),但并非在所有情况下都有效,只需两次(或两次以上)设定相同的键。 例如:
{
"param" : "This is the comment place",
"param" : "This is value place",
}
所以JSON会理解这一点:
{
"param" : "This is value place",
}
推荐文章
- 如何合并2 JSON对象从2个文件使用jq?
- 在VS Code中禁用“Comments are not allowed In JSON”错误
- 如何在Kotlin解析JSON ?
- JSON文件的蒙古导入
- 如何用jQuery / JavaScript解析JSON数据?
- jQuery在请求体中发布有效的json
- 将JSON显示为HTML
- Swift:理解// MARK
- 在JSON键名中哪些字符是有效的/无效的?
- 如何JSON序列化集?
- 如何检查JSON键是否存在?
- 在构建中编写注释的语法是什么?gradle文件?
- 将对象序列化为JSON
- node.js TypeError:路径必须是绝对路径或指定根路径到res.sendFile[解析JSON失败]
- Python json。loads显示ValueError:额外数据