使用GTM发布的JSON-LD的结构化数据测试工具中的错误:“对象声明中缺少','或'}'。

时间:2019-01-07 20:35:15

标签: google-tag-manager json-ld

我正在尝试使用GTM和JSON-LD将结构化标记添加到商店页面。这是代码:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "SportingGoodsStore",
  "name": "SAIL",
  "image": "https://www.sail.ca/media/stores/z-12-lat_45.451220021743-lon_45.451220021743-510x350.png",
  "@id": "https://www.sail.ca/fr/nos-magasins/brossard",
  "url": "https://www.sail.ca/fr/nos-magasins/brossard",
  "telephone": "450 321-1835",
  "priceRange": "$$",
  "address": {
    "@type": "PostalAddress",
    "streetAddress": "8780, boul. Leduc",
    "addressLocality": "Brossard",
    "addressRegion": "QC",
    "postalCode": "J4Y 0G4",
    "addressCountry": "CA"
  },
  "geo": {
    "@type": "GeoCoordinates",
    "latitude": 45.4514453,
    "longitude": -73.44171039999998
  },
  "openingHoursSpecification": [{
    "@type": "OpeningHoursSpecification",
    "dayOfWeek": [
      "Monday",
      "Tuesday"
    ],
    "opens": "10:00",
    "closes": "18:00"
  },{
    "@type": "OpeningHoursSpecification",
    "dayOfWeek": [
      "Wednesday",
      "Thursday",
      "Friday"
    ],
    "opens": "10:00",
    "closes": "21:00"
  },{
    "@type": "OpeningHoursSpecification",
    "dayOfWeek": "Saturday",
    "opens": "09:00",
    "closes": "17:00"
  },{
    "@type": "OpeningHoursSpecification",
    "dayOfWeek": "Sunday",
    "opens": "10:00",
    "closes": "17:00"
  }]
}
</script>

此代码使用GTM中的自定义HTML标记插入到我的页面上,并发布在商店页面上。使用https://jsonlint.com/,我确保JSON-LD似乎有效。但是,当我使用Google的结构化数据测试工具扫描URL时,仍然收到以下错误消息:

  

在对象声明中缺少','或'}'。

更糟糕的是,当我使用“代码段”测试而非URL测试将代码复制粘贴到结构化数据测试工具中时,没有错误消息。

您知道我在做什么错吗?

1 个答案:

答案 0 :(得分:0)

(问题中包含的JSON-LD与链接文档中的JSON-LD不同。以下内容基于链接的文档。)

您的JSON-LD包含以下内容:

"description": "<p style="margin-bottom: 0cm;">HTML with &eacute; and <strong>more HTML</strong></p>",

错误是该值包含未转义的"字符。因此,JSON-LD将被解析为

"description": "<p style=",

,其余内容将使其无效。

要解决此问题,您必须将值"中的任何\"转义,例如:

"description": "<p style=\"margin-bottom: 0cm;\">HTML with &eacute; and <strong>more HTML</strong></p>",

(请注意,理想情况下,您会使用use plain text instead of HTML in the value。Schema.org的description属性不需要HTML值。)