【发布时间】:2019-11-15 21:30:18
【问题描述】:
JSON-LD 类型的文档明确指出您可以为一个节点定义多种类型。 https://www.w3.org/TR/json-ld11/#specifying-the-type 如果从JSON-LD playground 中的上述url 打开示例#14,您将看到它是一个有效的语法。
{
"@id": "http://me.markus-lanthaler.com/",
"@type": [
"http://schema.org/Person",
"http://xmlns.com/foaf/0.1/Person"
]
}
但是,如果您尝试将此定义移动到 @context 中,并将其应用于特定属性,您将收到来自解析器的错误。检查它here。
{
"@context": {
"some_property": {
"@id": "http://me.markus-lanthaler.com/",
"@type": [
"http://schema.org/Person",
"http://xmlns.com/foaf/0.1/Person"
]
}
},
"some_property": "value"
}
显示的错误是: jsonld.SyntaxError:无效的 JSON-LD 语法; @context @type 值必须是字符串。
我仔细阅读了文档,它说您可以为节点类型定义多种类型,但不能为值对象定义。 documentation 明确表示,当@value 和@type 在同一个字典中使用时,@type 关键字表示一个值类型。否则,@type 关键字表示节点类型。 但here 是另一个例子,表明这可能不是真的。
有人知道如何在@context 中定义多个节点类型吗?
【问题讨论】:
标签: json-ld