我想用JSON-LD呈现一本平装本和电子书格式的书。

当我添加另一个mainEntity时,结构化数据测试工具会发现重复的键:

            <script type="application/ld+json">
            {
                  "@context": "http://schema.org",
                  "@type": "WebPage",
                  "mainEntity":{
                          "@type": "Book",
                          "author": "http://mywebsite.com/authors",
                          "bookFormat": "http://schema.org/EBook",
                          "datePublished": "2017-08-26",
                          "image": "http://mywebsite.com/images/coverImage.jpg",
                          "inLanguage": "en-US",
                          "isbn": "ebook isbn",
                          "name": "my website",
                          "numberOfPages": "200",
                          "offers": {
                            "@type": "Offer",
                            "availability": "http://schema.org/InStock",
                            "price": "30",
                            "priceCurrency": "USD"
                          },
                  "mainEntity":{
                          "@type": "Book",
                          "author": "http://mywebsite.com/authors",
                          "bookFormat": "http://schema.org/Paperback",
                          "datePublished": "2017-08-26",
                          "image": "http://mywebsite.com/images/coverImage.jpg",
                          "inLanguage": "en-US",
                          "isbn": "book isbn",
                          "name": "my website",
                          "numberOfPages": "200",
                          "offers": {
                            "@type": "Offer",
                            "availability": "http://schema.org/InStock",
                            "price": "55",
                            "priceCurrency": "USD"
                          },
                          "publisher": "Publisher name",
                        }
                }
            </script>


您能告诉我实现它的最佳方法吗?

最佳答案

如果一个属性有多个值,则必须将一个属性与array value (with [])一起使用,而不是重复该属性:

<script type="application/ld+json">
  {
    "@context": "http://schema.org",
    "@type": "WebPage",
    "mainEntity":
    [
      {
        "@type":"Book"
      },
      {
        "@type":"Book"
      }
    ]
  }
</script>

07-24 09:55