我能否在以下发言中发表一些意见?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 编码中的数据非独有的表达方式。 这允许 。*在RFC第二节“允许在六个结构字符中的任何字符之前或之后使用白色空间”。

*RFC 仅声明“ 允许在六个结构字符之前或之后使用白色空间”, 没有明确提及字符串、 数字、 “ false ”、“ true ” 和“ null ” 。 在所有执行中忽略了这一遗漏 。


首先,用简单化的方式 将你的JSON化为金字塔:

$jsonMin = json_encode(json_decode($json));

然后将您的评论编码为二进制 :

$hex = unpack('H*', $comment);
$commentBinary = base_convert($hex[1], 16, 2);

然后将您的二进制评分:

$steg = str_replace('0', ' ', $commentBinary);
$steg = str_replace('1', "\t", $steg);

以下是您的输出 :

$jsonWithComment = $steg . $jsonMin;

其他回答

没有 No.

JSON 仅限数据。 如果您包含一个注释, 那么它也一定是数据 。

您可以使用指定数据元素"_comment"使用JSON数据的应用程序应该忽略(或某事)这一点。

在产生/接收JSON的进程中,你最好有评论,因为他们应该知道JSON的数据会是什么,或者至少知道它的结构。

但如果你决定:

{
   "_comment": "comment text goes here...",
   "glossary": {
      "title": "example glossary",
      "GlossDiv": {
         "title": "S",
         "GlossList": {
            "GlossEntry": {
               "ID": "SGML",
               "SortAs": "SGML",
               "GlossTerm": "Standard Generalized Markup Language",
               "Acronym": "SGML",
               "Abbrev": "ISO 8879:1986",
               "GlossDef": {
                  "para": "A meta-markup language, used to create markup languages such as DocBook.",
                  "GlossSeeAlso": ["GML", "XML"]
               },
               "GlossSee": "markup"
            }
         }
      }
   }
}

考虑使用雅姆勒它几乎是JSON的超集(几乎所有有效的JSON都是有效的YAML),它允许评论。

JSON不支持评论,也从未打算用于需要评论的配置文件。

Hjson 是人类的配置文件格式。 放松语法, 减少错误, 更多评论 。

Hjson intro

见见(hjson.github.io) (hjson. github. iio) (hjson. github.) (吉森. 吉图布. io)JavaScript、Java、Python、PHP、Rust、Go、Ruby、C++和C#图书馆的JavaScript、Java、Java、Java、Python、PHP、Rust、Go、Ruby、C++和C#图书馆。

您可以使用 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 }

另见:硫酸脱硫, - - 贬 - 贬 - 贬 - 贬 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音 - 音

您可以通过正则表达式使用简单的预处理。例如,以下函数将解码在 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风格的评论: / *, #, / /。 字符串的字句保留不变 。