我在这里复制了json-ld 标准示例的一部分:
{
"@context":
{
"foaf": "http://xmlns.com/foaf/0.1/",
"picture": { "@id": "foaf:depiction", "@type": "@id" }
},
"picture": "http://twitter.com/account/profile_image/markuslanthaler"
}
Run Code Online (Sandbox Code Playgroud)
我不明白,为什么我们应该在@context 中使用@id。它应该是:
{
"@context":
{
"foaf": "http://xmlns.com/foaf/0.1/",
"picture": { "@type": ["@id", "foaf:depiction"] }
},
"picture": "http://twitter.com/account/profile_image/markuslanthaler"
}
Run Code Online (Sandbox Code Playgroud)
你有什么解释吗?
几年后:
我猜上面的意思是更可重用的形式:
{
"http://xmlns.com/foaf/0.1/depiction": "http://twitter.com/account/profile_image/markuslanthaler"
}
Run Code Online (Sandbox Code Playgroud)
如果我们先检查展平的表格并尝试逐渐压缩它,会更容易理解。所以@id是属性的 IRI 和@type值的类型,这里是@id,这可能会令人困惑,但这只是意味着我们期望 IRI 作为值。
什么是以JSON-LD返回SPARQL查询结果的最佳方法,最好保持在标准化JSON格式附近?是否可以为每个查询或仅针对某些查询类型返回JSON-LD?
JSON格式的SPARQL查询结果示例(即,不进行JSON-LD扩展):
{
"head": {"vars": ["s", "p", "o" ]},
"results": {
"bindings": [
{
"s": {
"type":"uri",
"value":"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
},
"p": {
"type":"uri",
"value":"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
},
"o": {
"type":"uri",
"value":"http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud) 在我的jbuilder模板中,我无法使用以"@"符号开头的键.例如"@context".我该怎么办.
在我的应用程序中,我需要这样的密钥用于json-ld元数据.
我想让json像下面一样
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Article",
"publisher": "The Ghost Blog",
"author": {
"@type": "Person",
"name": "John O'Nolan",
"image": "http://blog.ghost.org/content/images/2013/Nov/gravatar_j7_200.jpg",
"url": "http://blog.ghost.org/author/john",
"sameAs": "http://twitter.com/JohnONolan"
},
"headline": "11 Tools We Use at Ghost for Distributed Teams & Digital Nomads",
"url": "http://blog.ghost.org/distributed-team-tools/",
"datePublished": "2014-12-15T14:09:18.000Z",
"dateModified": "2014-12-18T22:13:49.000Z",
"image": "http://blog.ghost.org/content/images/2014/12/ghostdistrib.jpg",
"keywords": "Remote Work",
"description": "Doing remote work is tough. The freedom is great, but distributed team tools and communication are essential to making it work. Here are our top apps...."
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用schema.org作为lanquage在我的网站上使用json-ld.
原因是协助搜索引擎的抓取工具了解我的网站.
Schema.org为Items of Items提供了许多键/值属性对.
有时,这些键的值本身就是具有自己的Type的Item,并且具有自己的一组键/值对.
在实践中,相同的项目是几个不同键的适当答案,并且希望给出该项目的键/值集是必要的/必要的.
例如,在我的情况下,我正在使用schema.org的"WebPage"类型在网站上标记网页.
我想给出与WebPage类型上的各种键的答案相同的人:author,creator,copyrightHolder等.
我想我每次都可以用以下的方式重复这些值:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type" : "WebPage",
"name" : "The Name of the Webpage",
"author" :
{
"@type" : "Person",
"name" : "Tim"
}
"creator":
{
"@type" : "Person",
"name" : "Tim"
}
"copyrightHolder" :
{
"@type" : "Person"
"name" : "Tim",
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
然而,这对我来说是重复和冗长的.
我宁愿分配/定义一次这个人,然后根据需要使用关键字引用他(我).
我不太了解json-ld或编码/编程,作为一个外行人,我发现信息(spec + jsonld.org + here)有点令人困惑.
据我所知,除了将相关的"语言"声明为schema.or之外,还可以为文档(此处为网页)扩展@context以定义"事物",并且json-ld似乎也支持使用'引用特定项目' IRI'作为身份证.
因此,似乎我可以根据需要定义Person一次,类似于以下内容:
<script type="application/ld+json">
{
"@context":
["http://schema.org",
{
"Tim" :
{
"@type" : "Person",
"@id" : …Run Code Online (Sandbox Code Playgroud) 假设我有一个 JSON 对象,其中嵌套对象中有一些属性。
{
"title": "My Blog Post",
"meta": {
"publishedAt": "2016-08-01T00:00:00Z"
}
}
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法可以将 a 添加@context到我的顶级对象来达到这些属性(即只是“传递”元对象)?沿着这些思路:
{
"@context": {
"title": "schema:name",
"meta.publishedAt": {
"@type": "xsd:date",
"@id": "schema:datePublished"
}
},
"@id": "/my-article",
"title": "My Blog Post",
"meta": {
"publishedAt": "2016-08-01T00:00:00Z"
}
}
Run Code Online (Sandbox Code Playgroud)
我想避免必须添加(重复)@id到嵌套对象,否则我将如何解决它:
{
"@context": {
"title": "schema:name",
"meta": { "@id": "_:meta", "@container": "@set" },
"publishedAt": {
"@type": "xsd:date",
"@id": "schema:datePublished"
}
},
"@id": "/my-article",
"title": "My Blog Post",
"meta": {
"@id": "/my-article",
"publishedAt": "2016-08-01T00:00:00Z"
} …Run Code Online (Sandbox Code Playgroud) JSON-LD脚本Rich Card展示在SERP尝试创建用户定义的变量以及标签本身使用的脚本时。使用GTM的预览和调试功能时。我收到以下错误:
此语言功能仅支持 ECMASCRIPT6 模式或更好的模式:让声明。使用 --language_in=ECMASCRIPT6 或 ECMASCRIPT6_STRICT 启用 ES6 功能。
我明白……或者至少我认为我明白我需要告诉编译器
使用 --language_in=ECMASCRIPT6 或 ECMASCRIPT6_STRICT
但是我如何做到这一点?
<script>
(function(){
// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name default.js
// @language_in=ECMASCRIPT6_STRICT;
// @language_out=ES5_STRICT;
// ==/ClosureCompiler==
"use strict";
let data = {
"@context": "http://schema.org",
"@type": "MovingCompany",
"name": "WDA Movers",
"logo" : {
"@type" : "ImageObject",
"url" : "http://wda-moving.online/images/logo.jpg",
"height" : 435,
"width" : …Run Code Online (Sandbox Code Playgroud) compiler-errors google-tag-manager ecmascript-6 json-ld google-rich-snippets
尝试从json-ld解析JSON
这是下面的JSON:
{
"@context": "http://json-ld.org/contexts/person.jsonld",
"@id": "http://dbpedia.org/resource/John_Lennon",
"name": "John Lennon",
"born": "1940-10-09",
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}
Run Code Online (Sandbox Code Playgroud)
所以我想这样做:
var jsonData= {
"@context": "http://json-ld.org/contexts/person.jsonld",
"@id": "http://dbpedia.org/resource/John_Lennon",
"name": "John Lennon",
"born": "1940-10-09",
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
};
console.log(jsonData.@context);// Error:Uncaught SyntaxError: Invalid or unexpected token
console.log(jsonData.name);// John Lenon
Run Code Online (Sandbox Code Playgroud)
那我该如何解析@context?请提出建议。
我已经在这个问题上看到了另一个类似的问题,但是没有接受正确的答案或示例。此元素的格式应该是什么?BreadcrumbList有充分的文档证明,其中包含列表,但不包含SiteNavigationElement。
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "SiteNavigationElement",
"@graph": [
{
"@type": "ListItem",
"position": 1,
"item": {
"@id": "http://www.example.com/",
"url": "http://www.example.com/",
"name": "Home"
}
},
{
"@type": "ListItem",
"position": 2,
"item": {
"@id": "http://www.example.com/contact.html",
"url": "http://www.example.com/contact.html",
"name": "Contact"
}
},
]
}
</script>
Run Code Online (Sandbox Code Playgroud)
更新:
一直在玩,并想出了一些可行的方法。但是它的结构正确吗?
<script type="application/ld+json">
//<![CDATA[
{
"@context": "https:\/\/schema.org\/",
"@type": "SiteNavigationElement",
"headline": "Headline for Site Navigation",
"name": [
"Home",
"Tours",
"Transfers",
"Taxis",
"Contact"
],
"description": [
"Homes Desc.",
"Tours Desc.",
"Transfers Desc.",
"Taxis Desc.",
"Contact Desc."
],
"url": …Run Code Online (Sandbox Code Playgroud) Schema.org、Goodrelations-vocabulary.org 和 Productontology.org 之间是什么关系?
Schema.org 告知,“W3C schema.org 社区组是该项目的主要论坛”。谷歌、微软、雅虎和 Yandex 都是创始公司。
Google、Microsoft、Yahoo 和 Yandex 是否也接受 Goodrelations-vocabulary.org 和 Productontology.org 标准?如果没有,将来使用它们是个好主意吗?
虽然谷歌没有提到,但我读到谷歌处理结构化数据的方法存在一些差异。Schema.org 提供 Microdata,Google 提供 application/ld+json 等。
不可能说 Google 100% 适合 Schema.org。微软、雅虎和 Yandex 也是如此。
在 Schema.org 上没有发布“游艇宪章”的结构化方式,唯一的方式是http://www.productontology.org/doc/Yacht_charter,但这不是官方的(直到今天 13.03.2018)。
为游艇租赁行业发布结构化数据的最佳方式是什么?
我们是否必须使用Offer,AggregateOffer或http://www.productontology.org/doc/Yacht_charter?
我有一个JSON-LD文档,其中基本前缀没有像我期望的那样扩展,但首先缩短到它的根,然后@id附加数据:
{
"@context": {
"tag": "@type",
"@base": "http://example.com/base#auth-1/",
"Line": "lit:Line",
"load": "book:load",
"book": "http://gerastree.at/auth-1/",
"lnum": "lit:lnum",
"lline": {
"@language": "deu",
"@id": "lit:lines"
},
"lit": "http://gerastree.at/lit_2014#",
"lid": "@id"
},
"loadid": "loadIDstring",
"load": [
{
"tag": "Line",
"lnum": 1,
"lline": "asdf1",
"lid": "1"
},
{
"tag": "Line",
"lnum": 2,
"lline": "asdf2",
"lid": "2"
}
]
}
Run Code Online (Sandbox Code Playgroud)
然后RIOT(或操场)给出:
riot --syntax=jsonld --output=turtle lines.jsonld
@prefix lit: <http://gerastree.at/lit_2014#> .
@prefix book: <http://gerastree.at/auth-1/> .
_:b0 book:load <http://example.com/1> ;
book:load <http://example.com/2> .
<http://example.com/1>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> lit:Line ; …Run Code Online (Sandbox Code Playgroud) json-ld ×10
json ×3
schema.org ×3
base-url ×1
ecmascript-6 ×1
javascript ×1
jbuilder ×1
microdata ×1
navigation ×1
rdfa ×1
sparql ×1