schema.org - 如何将 JSON-LD 和微数据与 itemid 结合在一起?

标签 schema.org microdata json-ld structured-data

我想将两种结构化数据结合在一起:WebPage(JSON-LD)和BreadcrumbList(内联微数据)。

该主题不重复!我在 SO 上看到了许多关于该主题的类似回答问题 - 但我使用 Google 结构化数据测试工具对每个人进行了测试,但没有一个答案经过有效测试。

代码示例是:

<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Webpage",
"id": "https://www.example.com#Webpage",
"breadcrumb": {
"@type": "BreadcrumbList",
"@id": "https://www.example.com#BreadcrumbList"
}
}
</script>
<nav class="breadcrumbs">
<ol itemscope itemtype="http://schema.org/BreadcrumbList" itemid="https://www.example.com#BreadcrumbList">
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<a itemprop="item" rel="up up up" title="a" href="/a/">
<span itemprop="name">a</span></a>
<meta itemprop="position" content="1" /></li>
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<a itemprop="item" rel="up up" title="b" href="/b/">
<span itemprop="name">b</span></a>
<meta itemprop="position" content="2" /></li>
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<a itemprop="item" rel="up" title="c" href="/c/">
<span itemprop="name">c</span></a>
<meta itemprop="position" content="3" /></li>
</ol>
</nav>

正如我所说,WebPage 是 JSON-LD 片段中的主要数据类型。它有辅助数据类型 BreadcrumbList,它有一个 id。微数据内的 BreadcrumbList 与 itemid 相关,与 JSON-LD 中的相同 - 我希望测试工具显示 JSON-LD 中的 BredcrumbList 与微数据中的 BredcrumbList 之间的关系。但事实并非如此:测试工具将它们显示为不同的,并在 JSON-LD 代码段中触发错误,因为它不需要 ItemList

这是测试工具的错误还是我遗漏了一些实质性的东西?

PS:相同的结构,仅在 JSON-LD 上构建,已按预期进行验证:

<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Webpage",
"id": "https://www.example.com#Webpage",
"breadcrumb": {
"@type": "BreadcrumbList",
"@id": "https://www.example.com#BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem", 
"id": "https://www.example.com#ListItem"
}
]
}
}
</script>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "ListItem",
"id": "https://www.example.com#ListItem",
"position": "1",
"item": {
"@id": "https://www.example.com/item1",
"name": "name1"
}
}
}
</script>

最佳答案

我已经解决这个问题大约一个月了;它变得很快。

所以,JSON+LD只是linked data的容器。我认为你的问题属于“你能混合微格式吗”领域,即:模式、RDFa、微数据..答案是 Yes !

我使用 json+ld 格式为 Google 提供顶级链接定义;一些有点抽象的东西,比如组织、本地业务等。为了更深入地细化,我使用 RDFa/Microdata 内联作为页面元素。诸如面包屑、标题、电话等内容。

Google 支持每种微格式(对于 JSON-LD,使用 preference)并且当 mixing Attributes 时似乎没有任何冲突。只要数据链接是 consistent并且语法是有效的。这样您就可以使用适合代码结构的内容。

因此,根据 Google 开发文档和优秀开发人员的说法,您的代码示例是一种有效的方法,并且截至 2019 年,此方法创建了一个有效的页面。它使开发变得更加容易。

关于schema.org - 如何将 JSON-LD 和微数据与 itemid 结合在一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53885594/

相关文章:

html - 结构化数据 (schema.org) - EducationalOrganization 开放时间

html - 如何将 'name' 和 'url' 属性添加到同一个标签?

schema.org - 谷歌 SDTT : "The property ' availability' is not recognized by Google for an object of type Product"

html - FAQ 页面的 Schema.org

JSON-LD:值的名称是必需的吗?

html - JSON-LD 和元标记

seo - 内页的模式数据

reactjs - 如何在 React+Typescript 中使用微数据?

javascript - 如何在页面加载后异步修改 header 中的 JSON-LD

HTML5 和 Schema.org,为什么要同时使用?