html - head 中存在重复的 JSON-LD 脚本

标签 html json-ld structured-data

我必须将 JSON-LD 数据的多个 script 元素注入(inject)到我的应用程序的 head 中,所有元素都属于相同的 @type 。这是因为从不同的数据源提取不同的字段。

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

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

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

我希望 Google 能够将其简单地翻译为:

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

是吗?

最佳答案

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

JSON-LD 允许您指定不同对象中描述的内容是相同的:为它们提供相同的 @id 值。

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

参见Node Identifiers在 JSON-LD 规范中。

所以它可能看起来像这样(使用 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/下提供此 JSON-LD 以及有关组织的信息42.)

关于html - head 中存在重复的 JSON-LD 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45876849/

相关文章:

javascript - 在 Angular 组件模板中添加脚本标签

seo - 使用具有审查权限的结构化数据标记

html - 浏览器中的 CSS 定位不一致

android - HTML CSS 文本的最后一个字符开始一个新行

javascript - Firefox 中的键盘输入

javascript - 如何启用横向折叠

java - JSONLD : How to convert a json into JsonLD?

schema.org - 不同 Schema.org 类型的几个 JSON-LD 脚本 : why they're combined into one type when testing with Google SDTT?

seo - AMP 项目是否仅对 schema.org/NewsArticle 有用?

schema.org - 为什么 Google 测试工具使用 "id"属性来生成微数据项的 URL?