【问题标题】:Can I use @id to join multiple JSON-LD scripts to a valid object?我可以使用@id 将多个 JSON-LD 脚本连接到一个有效对象吗?
【发布时间】:2018-12-28 07:21:53
【问题描述】:

这有效吗?我需要一个机会将一页上的不同脚本块加入到有效对象中。

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Product",
  "@id": "#111",
  "description": "Test description",
  "name": "My Product"
}
</script>
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Product",
  "@id": "#111",
  "aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": "3.5",
    "reviewCount": "11"
  }
}
</script>

【问题讨论】:

标签: schema.org json-ld google-rich-snippets


【解决方案1】:

为什么要加入这些脚本?它们描述了相同的产品,并且部分是多余的。

但是,如果您正在寻找通过 id 加入脚本的可能性 - 是的,它存在。 IE。您有两个脚本:第一个 - 产品及其评级,第二个 - 提供此产品的组织。在这种情况下,连接看起来像:

<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"makesOffer": {
"@type": "Offer",
"itemOffered": {
"@type": "Product",
"@id": "https://www.example.com#111"
}
}
}
</script>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Product",
"id": "https://www.example.com#111",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "3.5",
"reviewCount": "11"
}
}
</script>

【讨论】:

    【解决方案2】:

    当评论系统将自己的标记单独添加到产品标记时,我经常这样做。它工作正常。

    您可以在结构化数据测试工具中对其进行测试。它应该将两者合二为一。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多