头部中有重复的JSON-LD脚本 [英] Duplicate JSON-LD scripts in head
问题描述
我必须将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屋!