我发现很难将几个或几个JSON-LD标记合并为一个新手。你能告诉我我做错了吗?
当我在Google结构化数据测试工具中输入以下标记时,它仅显示Organization
模式类型的结果,而BreadcrumbList
类型也是如此。
<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>
答案 0 :(得分:9)
要指定多个顶级项目,您有三个选项:
<script type="application/ld+json">
[
{
"@context": "http://schema.org",
"@type": "Organization"
},
{
"@context": "http://schema.org",
"@type": "BreadcrumbList"
}
]
</script>
缺点:您必须为每个项目重复@context
。
@graph
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@graph":
[
{
"@type": "Organization"
},
{
"@type": "BreadcrumbList"
}
]
}
</script>
script
元素<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization"
}
</script>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList"
}
</script>
缺点:您必须为每个项目重复script
元素和@context
。
但通常最好只提供一个顶级项目,并将其他项目嵌套在合适的属性下。但是,这在所有情况下都是不可能的。
在您的情况下,似乎可以通过添加WebPage
项来实现,假设它是组织的页面,并且此页面具有此痕迹列表:
<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:为每个项目提供一个带@id
的URI,然后将这些URI作为属性值引用。)
答案 1 :(得分:2)
JSON连接不正确。如果你手动执行它,如果你有一个启用了JSON的编辑器(带有lint),那将非常有用。 Atom(https://atom.io)是一个很好的。
对于此特定示例,以下是更正后的版本:
[{
"@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"
}
}]}
]
PS:通常只是正确地格式化代码可以帮助发现简单的错误。