你如何结合几个JSON-LD标记? [英] How do you combine several JSON-LD markups?
问题描述
我发现很难将几个或几个JSON-LD标记合并为一个新手。您能告诉我我做错了什么吗?
当我在Google结构化数据测试工具中输入以下标记时,它只显示组织
模式类型,同时还有 BreadcrumbList
类型。
< script type =application / ld + json>
{
@context:http://schema.org,
@type:Organization,
legalName:示例INC,
logo:https://www.example.com/image.png,
url:https://www.example.com/,
sameAs:[
https://www.facebook.com/example,
https://www.linkedin.com/company/example,
https:/ /twitter.com/example,
https://www.youtube.com/user/example,
https://en.wikipedia.org/wiki/example
]
}
@type:BreadcrumbList,
itemListElement:[
{
@type:ListItem,
position:1,
item:{
@id:https://www.example.com/,
name:Homepage
}
}
]
< / script>
为了指定多个顶级项目,选项:
$ b
Array
< ; script type =application / ld + json>
[
{
@context:http://schema.org,
@type:组织
},
{
@context:http://schema.org,
@type:BreadcrumbList
}
]
缺点:您必须重复 @context
为每个项目。
@graph
< script type =application / ld + json>
{
@context:http://schema.org,
@graph:
[
{
@type :组织
},
{
@type:BreadcrumbList
}
]
}
多个脚本
元素
< script type =application / ld + json>
{
@context:http://schema.org,
@type:Organization
}
< / script>
< script type =application / ld + json>
{
@context:http://schema.org,
@type:BreadcrumbList
}
< / script>
缺点:您必须重复脚本
元素和 @context
为每个项目。
但它通常最好只提供一个顶层项目,并将其他项目嵌套在适当的属性下。尽管如此,这在所有情况下都是不可能的。
在你的情况下,通过添加一个 WebPage
项似乎是可能的,假设它是组织的页面,有这样的面包屑列表:
< script type =application / ld + json>
@context:http://schema.org,
@type:WebPage,
provider:
{
@type:Organization
},
breadcrumb:
{
@type:BreadcrumbList
}
}
< / script>
(您可以在不嵌套的情况下实现相同的功能:为每个项目指定一个包含 @id
的URI,然后将这些URI作为属性值引用。)
I'm finding it difficult to merge couple or several JSON-LD markups together being a novice. Could you please tell me what I'm doing wrong?
When I enter the following markup into Google Structured Data Testing Tool, it only shows results for the Organization
schema type while there's BreadcrumbList
type too.
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"legalName": "Example INC",
"logo": "https://www.example.com/image.png",
"url": "https://www.example.com/",
"sameAs": [
"https://www.facebook.com/example",
"https://www.linkedin.com/company/example",
"https://twitter.com/example",
"https://www.youtube.com/user/example",
"https://en.wikipedia.org/wiki/example"
]
}
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": "1",
"item": {
"@id": "https://www.example.com/",
"name": "Homepage"
}
}
]
</script>
For specifying multiple top-level items, you have three options:
Array
<script type="application/ld+json">
[
{
"@context": "http://schema.org",
"@type": "Organization"
},
{
"@context": "http://schema.org",
"@type": "BreadcrumbList"
}
]
</script>
Drawback: You have to repeat the @context
for each item.
@graph
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@graph":
[
{
"@type": "Organization"
},
{
"@type": "BreadcrumbList"
}
]
}
</script>
Multiple script
elements
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization"
}
</script>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList"
}
</script>
Drawback: You have to repeat the script
element and the @context
for each item.
But it’s typically preferable to provide only one top-level item, and nest the additional items under suitable properties. This is not possible in all cases, though.
In your case it seems to be possible by adding a WebPage
item, assuming it’s the organization’s page and this page has this breadcrumb list:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebPage",
"provider":
{
"@type": "Organization"
},
"breadcrumb":
{
"@type": "BreadcrumbList"
}
}
</script>
(You can achieve the same without nesting: give each item a URI with @id
, and then reference these URIs as property values.)
这篇关于你如何结合几个JSON-LD标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!