`head` 部分中的 `<script type='application/ld+json'>{jsonObj}</script>` 是做什么的?

What's a `<script type='application/ld+json'>{jsonObj}</script>` in a `head` section do?

我明白了 link 但不是很明白。锯:

<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type": "WebSite",
    "url": "http://website.com",
    "name": "wbs",
    "description": "Web Studio"
}
</script>

在源代码中。

我网站中的上述代码片段 header 如何帮助我或我的网站?

它提供 Google 和其他爬虫有关网站的结构化数据。这用于丰富的摘要和知识图面板等。查看此站点以获取更多信息:https://developers.google.com/search/docs/guides/intro-structured-data

在您的示例中,script 元素是 used as data block, which contains JSON-LD (type="application/ld+json")。

JSON-LD是一个RDF serialization. It allows you to publish Linked Data (or structured data) using JSON. In your example, the vocabulary Schema.org用的("@context": "http://schema.org").

任何感兴趣的消费者都可以使用此结构化数据。主要消费者是搜索引擎 Bing、Google、Yahoo 和 Yandex,它们支持使用词汇 Schema.org 的结构化数据。他们的一个用例是在结果片段中显示更多详细信息。

您的示例可能不会生成这样的增强代码段。如果您想知道搜索引擎提供的功能以及必须为此提供哪些结构化数据,则必须查看搜索引擎的文档。例如,Google 使用 WebSite 类型(在您的示例中使用)作为它们的 Sitelinks Search Box,但您必须另外添加一个 potentialAction(用于搜索功能).

这是在您的站点中包含结构化数据的一种方法,可以帮助任何类型的 users/crawlers 以有效的方式使用站点上的信息。最流行的例子是 Google 新闻卡片:

这种卡片数据实际上是来自结构化数据。

包含结构化数据的其他方法是通过 Microdata

而问这个问题的时候,我对这些一无所知。现在我为一些发布商处理结构化数据。

您得到的代码段是一个包含JSON-LD data format, a method of encoding Linked Data using JSON. Schema.org词汇表的脚本,用于标记网页内容,以便主要搜索引擎(Google、Microsoft、Yandex 和 Yahoo!)可以理解它们.搜索引擎使用此信息来显示以向用户显示相关内容。例如,您的网站具有众所周知的品牌名称,例如编码器。搜索引擎会将其解释为为软件编写代码的人。为了帮助搜索引擎更好地解释这一点,您需要使用 Schema.org 词汇表提供数据。 例如

<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type": "WebSite",
    "url": "https://coder.com",
    "name": “Coder”,
    "description": “Platform to learn code”
}
</script>

我写了这个 JavaScript 代码让用户在 Google 上写下你的品牌名称。 搜索表单将显示给用户。 用户只需输入您的品牌名称即可显示此搜索,它最常用于首页。 要使用此代码,请复制 JavaScript 并将其粘贴到主要内容最后一行的底部,不用担心 JavaScript 代码不会向用户显示,只会出现在 Google 结果。

<script type="application/Id+json"> { 
    "@context": "schema.org", 
    "@type": "WebSite", "url": "coolernew.com", "potentialAction": { 
        "@type": "SearchAction", "target": "query.example.com/search?q={search_term_string}", "query-input": "required name=search_term_string" 
        } 
    } </script>
<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type": "WebSite",
    "url": "http://website.com",
    "name": "wbs",
    "description": "Web Studio"
}
</script>

上面的代码片段是一个嵌入在 HTML 中的基于 JSON-LD 的结构化数据岛(或块),它向用户代理(软件应用程序)提供数据以进行额外处理。此数据可以采用元数据的形式,通知所述用户代理有关主机文档的性质。

例如,您可以通过嵌入以下结构化数据岛来通知用户代理(例如 Google 的爬虫)与文档关联的人员的身份:

## JSON-LD Start ##  
{
    "@context": "https://schema.org",
    "@type": "Person",
    "@id": "https://stackexchange.com/users/74272/kingsley-uyi-idehen#me",
    "mainEntityOfPage": "https://stackexchange.com/users/74272/kingsley-uyi-idehen",
    "sameAs": "https://stackexchange.com/users/74272/kingsley-uyi-idehen",
    "name": "Kingsley Uyi Idehen",
    "description": "@kidehen Identified at Web, relatively"
}
## JSON-LD End ##

这是可能的,因为 schema:sameAs 属性 的语义认为它是唯一标识的。

您还可以将浏览器扩展(例如我们的结构化数据嗅探器)添加到您现有的浏览器中,该浏览器了解使用 部署的结构化数据岛的强大功能,生成所附屏幕截图中描述的内容。