文本可以用URIComponent编码而不是转义吗?

时间:2015-04-25 07:31:58

标签: json escaping encodeuricomponent

示例:

转义的文字(在文章中):

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "NewsArticle",
  "headline": "Article headline",
  "alternativeHeadline": "The headline of the Article",
  "image": ["thumbnail1.jpg", "thumbnail2.jpg"],
  "datePublished": "2015-02-05T08:00:00+08:00",
  "description": "A most wonderful article",
  "articleBody": "\"Hello!\" said Bob.\n\"Hi,\" said Jane, \"Go away.\""
}
</script>

用URIComponent编码的同一文本(再次在articleBody中):

    <script type="application/ld+json">
    {
      "@context": "http://schema.org",
      "@type": "NewsArticle",
      "headline": "Article headline",
      "alternativeHeadline": "The headline of the Article",
      "image": ["thumbnail1.jpg", "thumbnail2.jpg"],
      "datePublished": "2015-02-05T08:00:00+08:00",
      "description": "A most wonderful article",
      "articleBody": "%22Hello!%22%20said%20Bob.%0A%22Hi%2C%22%20said%20Jane%2C%20%22Go%20away.%22%0A"
    }
    </script>

1 个答案:

答案 0 :(得分:1)

你不能。 Google不会解析编码文本,这会导致编码字符出现在丰富的代码段/富卡中。

这是一个非常基本的示例 - 复制下面的代码并将其粘贴到Google's schema checker

<script type="application/ld+json">
{
  "@context": "http://schema.org/",
  "@type": "Recipe",
  "name": "Perfect%20Apple%20Pie",
  "image": "http://images.edge-generalmills.com/56459281-6fe6-4d9d-984f-385c9488d824.jpg"
}
</script>

点击“验证”,您会看到一个绿色的“预览”按钮。单击预览时,您将看到以下内容:

enter image description here