我能否在以下发言中发表一些意见?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如果有,如何处理?


当前回答

是 是新的标准,杰森5在许多 C+++ 样式批注中允许 C++ 样式批注其它延长:

// A single line comment.

/* A multi-
   line comment. */

JSON5 数据交换格式(JSON5)是JSON的超级组合,旨在减轻JSON的某些限制。它完全向后兼容,使用它可能比写自定义的非标准分析器、为现有分析器打开非标准功能或使用像字符串字段等各种黑客来评论要好一些。或者,如果正在使用的分析器支持的话,简单同意我们正在使用 JSON 5子集,即 JSON 和 C++ 样式注释。它比我们把JSON标准为我们所认为的合适.

已经存在npm 软件包包, Python 软件包包, Java 软件包C 图书馆库我认为没有理由坚持“官方的”JSON限制。

我认为,将JSON的评论从JSON删除的原因与在爪哇清除操作员超载的原因相同:可能会被错误地使用,但一些显然合理的使用案例却被忽视。对于操作员超载,它是矩阵代数和复杂数字。 对于JSON的评论,它是一个配置文件和其他文件,可以由人类而不是仅仅由分析员来撰写、编辑或阅读。

其他回答

你,你,你能够有评论意见的年份贾索普我只是花了一个小时 试图让程序与例如,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所以我不得不去掉那些评论

Dojo工具包 JavaScript工具包(至少是1.4版)允许您在 JSON 中加入评论。/* */Dojo 工具包使用JSONdojo.xhrGet()拨打。

其他JavaScript工具箱也可能同样发挥作用。

在选择最后选择之前先试验其他数据结构(甚至数据清单)时,这样做会有帮助。

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."
    }
}

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));

JSON并不支持本地的评论, 但您可以自己制作解码器或至少预处理器来删除评论, 这完全没问题(只要您只是忽略评论, 不使用它们来指导您的应用程序如何处理 JSON 数据 ) 。

JSON没有评论。 JSON 编码器必须输入输出评论。 JSON 编码器可能接受和忽略评论。

评论绝不应被用来传递任何有意义的信息。这就是JSON的目的。

参 :Douglas Crockford,Json Spec的作者,道格拉斯·克罗克福德.