【问题标题】:Duplicate JSON-LD scripts in head头部重复 JSON-LD 脚本
【发布时间】:2018-02-03 05:38:58
【问题描述】:

我必须将 JSON-LD 数据的多个 script 元素注入我的应用程序的 head,所有这些都属于同一个 @type。这是由于从不同的数据源中提取了不同的字段。

这种重复会导致任何问题吗?

<script type="application/ld+json">
    {
        "@type": "Organisation",
        "name": "John Smith"
    }
</script>

<script type="application/ld+json">
    {
        "@type": "Organisation",
        "city": "London"
    }
</script>

我希望这将被谷歌简单地翻译:

<script type="application/ld+json">
    {
        "@type": "Organisation",
        "name": "John Smith",
        "city": "London"
    }
</script>

是吗?

【问题讨论】:

    标签: html json-ld structured-data


    【解决方案1】:

    消费者不能/不应该假设这些 JSON 对象描述的是同一件事。 (想想一个包含许多不同组织信息的网页:假设它们是同一个组织当然是错误的。)

    JSON-LD 允许您指定不同对象中描述的事物是相同的:赋予它们相同的@id 值。

    @id 采用 IRI 作为标识符(它是 useful to provide them for many reasons)。

    请参阅 JSON-LD 规范中的 Node Identifiers

    所以它可能看起来像这样(使用 Schema.org 而不是您的自定义词汇表):

    <script type="application/ld+json">
        {
            "@context": "http://schema.org",
            "@type": "Organization",
            "@id": "/organizations/42#this",
            "name": "ACME"
        }
    </script>
    
    <script type="application/ld+json">
        {
            "@context": "http://schema.org",
            "@type": "Organization",
            "@id": "/organizations/42#this",
            "description": "…"
        }
    </script>
    

    (相对 URL /organizations/42#this 将代表组织本身。最好在 /organizations/42 下提供此 JSON-LD 以及有关该组织的信息。)

    【讨论】:

      猜你喜欢
      • 2019-01-12
      • 2016-05-21
      • 1970-01-01
      • 1970-01-01
      • 2015-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-12
      相关资源
      最近更新 更多