头部中有重复的JSON-LD脚本 [英] Duplicate JSON-LD scripts in head

查看:107
本文介绍了头部中有重复的JSON-LD脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to inject multiple script elements for JSON-LD data into the head of my application, all pertaining to the same @type. This is due to pulling in different fields from different data source.

此重复会引起任何问题吗?

Will this duplication cause any problems?

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

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

我希望Google可以将其翻译为:

I'm hoping this will be translated by Google as simply:

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

对吗?

推荐答案

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

Consumers can’t/shouldn’t assume that these JSON objects describe the same thing. (Think of a web page with information about many different organizations: it would of course be wrong to assume that they are the same organization.)

JSON-LD允许您指定在不同对象中描述的事物是相同的:为其赋予相同的@id值.

JSON-LD allows you to specify that the things described in different objects are identical: give them the same @id value.

@id使用一个IRI作为标识符(由于多种原因有用,可以提供它们).

@id takes an IRI which acts as identifier (it’s useful to provide them for many reasons).

请参见中的节点标识符 JSON-LD规范.

See Node Identifiers in the JSON-LD spec.

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

So it could look like this (using Schema.org instead of your custom vocabulary):

<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以及您有关组织的信息.)

(The relative URL /organizations/42#this would represent the organization itself. It’s best practice then to provide this JSON-LD as well your information about the organization under /organizations/42.)

这篇关于头部中有重复的JSON-LD脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆