0

我从我的服务器获取了一些代表搜索结果的 JSON。我从 Sphider 获得它,它是一个 PHP 搜索引擎。如果您有兴趣,我已经在此处首先询问了有关获取 JSON 的问题。

所以这个 JSON 对我来说看起来不错。当我把它放入这个验证器时,它说“发现无效字符。[代码 18,结构 66]”我不确定这是什么意思,但我想我应该更仔细地看看它抱怨的那一行如果有任何奇怪的字符。我发现的只是空格应该在的 0x20s(空格) 。

现在,我认为最大的提示是:当我将验证器输出中的“无效”JSON 复制到输入中并再次运行它时,它会起作用,说明 JSON 是有效的。我不知道该怎么做。

那么验证器是什么意思呢?此外,此文本是从数据库中提取的,是什么导致它输出“无效字符”?

这是 JSON:

{   "result_report":"Displaying results 1 - 2 of 2 matches (0.03 seconds) ",  "results":[    {   "idented":"false",   "num":"1",  "weight":"[100.00%]",  "link":"http://www.avtainsys.com/articles/PHP_Markdown",  "title":"PHP <b>Markdown</b>",   "description":"  Full documentation of <b>Markdown</b>'s syntax is available on John's <b>Markdown</b> page: http://daringfireball.net/projects/<b>Markdown</b>/   Installation and Requirement  PHP <b>Markdown</b> requires PHP version 4.0.5 or later.  WordPress  PHP <b>Markdown</b>",  "link2":"http://www.avtainsys.com/articles/PHP_Markdown",  "size":"31.0kb" },  {   "idented":"false",   "num":"2",  "weight":"[3.46%]",  "link":"http://www.avtainsys.com/articles",  "title":"Recent Articles",   "description":" systems         PHP <b>Markdown</b>     by Some Guy     Some information regarding using the PHP <b>Markdown</b> library, it's deployment, and some things to watch out for.            MD Example      by Hassan El-Mehalawi       A simple example",  "link2":"http://www.avtainsys.com/articles",  "size":"3.3kb" },  {  "num":"-1" }  ],  "other_pages":[   {  "title":"1",  "link":"search.php?query=markdown&start=1&search=1&results=10&type=and&domain=",      "active":"true"     }     ]  }

在这里它被格式化:

{
   "result_report":"Displaying results 1 - 2 of 2 matches (0.03 seconds) ",
   "results":[
      {
         "idented":"false",
         "num":"1",
         "weight":"[100.00%]",
         "link":"http://www.avtainsys.com/articles/PHP_Markdown",
         "title":"PHP <b>Markdown</b>",
         "description":"  Full documentation of <b>Markdown</b>'s syntax is available on John's <b>Markdown</b> page: http://daringfireball.net/projects/<b>Markdown</b>/   Installation and Requirement  PHP <b>Markdown</b> requires PHP version 4.0.5 or later.  WordPress  PHP <b>Markdown</b>",
         "link2":"http://www.avtainsys.com/articles/PHP_Markdown",
         "size":"31.0kb"
      },
      {
         "idented":"false",
         "num":"2",
         "weight":"[3.46%]",
         "link":"http://www.avtainsys.com/articles",
         "title":"Recent Articles",
         "description":" systems       PHP <b>Markdown</b>    by Some Guy   Some information regarding using the PHP <b>Markdown</b> library, it's deployment, and some things to watch out for.         MD Example    by Hassan El-Mehalawi   A simple example",
         "link2":"http://www.avtainsys.com/articles",
         "size":"3.3kb"
      },
      {
         "num":"-1"
      }
   ],
   "other_pages":[
      {
         "title":"1",
         "link":"search.php?query=markdown&start=1&search=1&results=10&type=and&domain=",
         "active":"true"
      }
   ]
}

需要明确的是,格式化的 JSON 是使用我上面链接的格式化程序/验证器格式化的。这是我输入原始“无效”输出后得到的输出。

由于观察到上述未格式化的 JSON 实际上是有效的,因此这里是输出上述 JSON 的 URL:

http://avtainsys.com/sphider/search.php?query=markdown&search=1

4

1 回答 1

4

它与标签有关;它在清除验证器标识的字符串中的空格后解析(来自实际源)。从技术上讲,标签应该像\tJSON 字符串一样被转义(尽管有些解析器可能不关心)。

于 2012-06-07T20:43:14.397 回答