JSON输出中的字符无效

时间:2012-06-07 20:12:04

标签: database json

我从服务器上获得了一些代表搜索结果的JSON。我从Sphider获得它,这是一个PHP搜索引擎。如果您有兴趣,我已经开始询问如何首先获取JSON here

所以这个JSON对我来说没问题。当我把它放入this validator时,它说的是“找到无效的字符。[代码18,结构66]”我不知道这意味着什么,但我想我应该看看它抱怨更多的线密切关注是否有任何奇怪的人物。我发现的只是0x20(空格),其中应该

现在,我认为这是最大的提示:当我将“无效”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

1 个答案:

答案 0 :(得分:4)

它与标签有关;它在清理验证器标识的字符串中的空格后解析(来自实际源)。技术上标签应该在JSON字符串中以\t进行转义(尽管某些解析器可能不关心)。