我有这个json-ld:
{ "@id": "http://www.example.com/john-doe",
"@type": "http://xmlns.com/foaf/0.1/Person",
"http://xmlns.com/foaf/0.1/name": "John Doe",
"http://xmlns.com/foaf/0.1/age": {
"@value": "42",
"@kind": "http://www.w3.org/2001/XMLSchema#nonNegativeInteger"},
"http://xmlns.com/foaf/0.1/knows" : [
{ "@id": "http://www.example.com/charlie-brown" },
{ "@id": "http://www.example.com/jane-doe" }
]
}
我必须编写上下文,以便下面的json-ld有效。
{ "@context" : "context to write....",
"@id": "john-doe",
"@type": "person",
"name": "John Doe",
"age": "42",
"knows": ["charlie-brown", "jane-doe"]
}
我已经写了一个解决方案,但它不完整,我无法弄清楚如何编写完整的解决方案,希望有人可以帮助我。
答案 0 :(得分:1)
您必须使用framing才能获得接近您要求的结果。
在json-ld playground中使用此link for an example。这是嵌入式@context的文档的样子:
{
"@context": {
"name": {
"@id": "http://xmlns.com/foaf/0.1/name"
},
"age": {
"@id": "http://xmlns.com/foaf/0.1/age"
},
"knows": {
"@id": "http://xmlns.com/foaf/0.1/knows",
"@container": "@set"
}
},
"@id": "john-doe",
"@type": "person",
"name": "John Doe",
"age": "42",
"knows": [
"charlie-brown",
"jane-doe"
]
}
这就是框架的外观如何
{
"@context": {
"name": {
"@id": "http://xmlns.com/foaf/0.1/name"
},
"age": {
"@id": "http://xmlns.com/foaf/0.1/age"
},
"knows": {
"@id": "http://xmlns.com/foaf/0.1/knows",
"@container": "@set"
}
}
}
这将呈现给
{
"@context": {
"name": {
"@id": "http://xmlns.com/foaf/0.1/name"
},
"age": {
"@id": "http://xmlns.com/foaf/0.1/age"
},
"knows": {
"@id": "http://xmlns.com/foaf/0.1/knows",
"@container": "@set"
}
},
"@graph": [
{
"@id": "john-doe",
"@type": "https://json-ld.org/playground/person",
"age": "42",
"knows": [
"charlie-brown",
"jane-doe"
],
"name": "John Doe"
}
]
}