首页 > 解决方案 > 我可以使用@id 将多个 JSON-LD 脚本连接到一个有效对象吗?

问题描述

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

<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.orgjson-ldgoogle-rich-snippets

解决方案


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

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

<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>

推荐阅读