如何在产品片段中添加多个评论?

7
我正在尝试使用JSON-LD创建一个包含多个评论的产品片段。当我只包含一个评论时,下面的代码可以正常工作(请复制并粘贴代码段到以下URL的控制台进行测试:https://search.google.com/structured-data/testing-tool)。然而,我不清楚如何添加多个评论。经过一段时间的努力,我仍无法让它正常工作,并且很难找到一个示例。
假设我有一个来自"John"的评论,他给产品评分为"3.0",另一个来自"Sarah"的评论,她给产品评分为"5.0"。如何在下面的代码中加入Sarah的评论?
 {
   "@context": "http://schema.org/",
   "@type": "Product",
   "name": "Samsung Galaxy S",  
   "description": "A great product",
   "brand": {
"@type": "Thing",
    "name": "Samsung"
},
"aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": "4.0",
    "reviewCount": "103"
},
"offers": {
    "@type": "Offer",
     "priceCurrency": "EUR",
     "price": "18",
     "itemCondition": "http://schema.org/NewCondition",
     "availability": "http://schema.org/InStock",
     "seller": {
        "@type": "Organization",
        "name": "Samsung"
    }

}
,"review": {
    "@type": "Review",
     "author": "John",
    "datePublished": " 7 December 2016",
    "description": "I love this product so much",
    "name": "Amazing",
    "reviewRating": {
         "@type": "Rating",
         "bestRating": "5",
         "ratingValue": "3.0",
         "worstRating": "1"
     }

}


}

1
你能否提供一个示例,展示一下你尝试过的内容? - unor
1
搜索google [数组]以了解如何构建一个[数组]。 - Jay Gray
2个回答

11
您可以将评论指定为数组。
<script type="application/ld+json">
{
  "@context": "http://schema.org/",
  "@type": "Product",
  "image": "http://www.example.com/iphone-case.jpg",
  "name": "The Catcher in the Rye",
  "review": [
    {
      "@type": "Review",
      "reviewRating": {
        "@type": "Rating",
        "ratingValue": "4"
      },
      "name": "iPhone 6 Case Plus",
      "author": {
        "@type": "Person",
        "name": "Linus Torvalds"
      },
      "datePublished": "2016-04-04",
      "reviewBody": "I loved this case, it is strurdy and lightweight. Only issue is that it smudges.",
      "publisher": {
        "@type": "Organization",
        "name": "iPhone 6 Cases Inc."
      }
    },
    {
      "@type": "Review",
      "reviewRating": {
        "@type": "Rating",
        "ratingValue": "4"
      },
      "name": "iPhone 6 Case Plus+",
      "author": {
        "@type": "Person",
        "name": "Linus Torvalds"
      },
      "datePublished": "2019-04-04",
      "reviewBody": "I loved this case, it is strurdy and lightweight. Only issue is that it smudges.",
      "publisher": {
        "@type": "Organization",
        "name": "iPhone 6 Cases Inc."
      }
    }
  ]
}

</script>

0

您可以将多个JSON-LD片段附加到单个页面上,因此您可以将评论数据从示例中删除并将其移动到独立的片段中。然后为“Sarah”创建另一个片段。

以下是评论的样板JSON-LD:

<script type="application/ld+json">
{
  "@context": "http://schema.org/",
  "@type": "Product",
  "image": "http://www.example.com/iphone-case.jpg",
  "name": "The Catcher in the Rye",
  "review": {
    "@type": "Review",
    "reviewRating": {
      "@type": "Rating",
      "ratingValue": "4"
    },
    "name": "iPhone 6 Case Plus",
    "author": {
      "@type": "Person",
      "name": "Linus Torvalds"
    },
    "datePublished": "2016-04-04",
    "reviewBody": "I loved this case, it is strurdy and lightweight. Only issue is that it smudges.",
    "publisher": {
      "@type": "Organization",
      "name": "iPhone 6 Cases Inc."
    }
  }
}
</script>

如果您在https://search.google.com/structured-data/testing-tool上测试多个代码片段,您会发现它将被验证。

作为替代方案,我已经在一个网站上实现了这个等效的功能。我已经删除了单独的评论并修改了您的aggregateRating块。

<script type="application/ld+json"> {
   "@context": "http://schema.org/",
   "@type": "Product",
   "name": "Samsung Galaxy S",  
   "description": "A great product",
   "brand": {
        "@type": "Thing",
        "name": "Samsung"
    },
    "aggregateRating": {
        "@type": "AggregateRating",
        "ratingValue": "4",
        "reviewCount": "103",
        "worstRating": "1",
        "bestRating": "5"
    },
    "offers": {
        "@type": "Offer",
        "priceCurrency": "EUR",
        "price": "18",
        "itemCondition": "http://schema.org/NewCondition",
        "availability": "http://schema.org/InStock",
        "seller": {
        "@type": "Organization",
        "name": "Samsung"
        }
    }
}</script>

祝你好运!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接