有没有办法强制单个对象到数组?每次测试对象类型真的很烦人.
我试过这个上下文,但它不起作用.在JSON-LD Playground中也有例子.使用此上下文,资源将转换为单个对象,而不是包含一个对象的数组,如您所料.
{
"@context": {
"member": {
"@id": "http://xmlns.com/foaf/0.1/member",
"@container": "@list"
},
"ex": "http://example.org/ex#",
"foaf": "http://xmlns.com/foaf/0.1/",
"owl": "http://www.w3.org/2002/07/owl#",
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"frapo": "http://purl.org/cerif/frapo/"
},
"@type": "foaf:Organisation",
"member": []
}
Run Code Online (Sandbox Code Playgroud)
结果:
... {
"@id": "ex:Organization_1",
"@type": "foaf:Organisation",
"foaf:member": {
"@id": "ex:Person_1",
"@type": "foaf:Person",
"foaf:name": "Bill"
}
} ...
Run Code Online (Sandbox Code Playgroud)
应该是什么:
"foaf:member": [{ "@id": ... }]
Run Code Online (Sandbox Code Playgroud)
使用"@container": "@set"而不是@list.
@list意味着秩序——但@set事实并非如此。JFYI,在压缩数据时,您的“成员”术语可能没有被选择(通过算法),因为您的输入与@list. 如果您的数据与上下文中的术语不匹配,则将使用匹配的替代术语(或完整网址)。简而言之,用@set它代替。
| 归档时间: |
|
| 查看次数: |
1001 次 |
| 最近记录: |