如何在产品代码段中添加多条评论?

时间:2017-12-01 03:20:09

标签: javascript json json-ld google-rich-snippets rich-snippets

我正在尝试使用多条评论在JSON-LD中创建产品代码段。当我只包含一个评论时,下面的代码有效。 (请在以下网址的控制台中复制粘贴代码片段以对其进行测试: https://search.google.com/structured-data/testing-tool )。但是我不清楚如何添加多个评论。经过一段时间的努力,我无法让自己工作,我很难找到一个例子。

我们说约翰""谁给予产品评级为" 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"
     }

}


}

2 个答案:

答案 0 :(得分: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>
祝你好运!

答案 1 :(得分:0)

您可以将评论指定为数组,

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