有没有办法始终使用 EasyRdf 将单个对象强制到数组?
如果 rdf:type
有多个值,我会得到一个像这样的数组。注意 @type
属性是一个数组。
{
"@context": {
"ethon": "http://ethon.consensys.net/",
"ethstats": "http://ethereum.ethstats.io/"
},
"@graph": [{
"@id": "ethstats:Uncle_0x5cd50096dbb856a6d1befa6de8f9c20decb299f375154427d90761dc0b101109",
"@type": ["ethon:Uncle", "ethon:Block"],
"ethon:blockCreationTime": "2015-07-30T15:26:58.000Z",
"ethon:blockHash": "0x5cd50096dbb856a6d1befa6de8f9c20decb299f375154427d90761dc0b101109",
"ethon:number": "1"
}]
}
但是如果只有一个 rdf:type
则 @type
属性不是数组。
{
"@context": {
"ethon": "http://ethon.consensys.net/",
"ethstats": "http://ethereum.ethstats.io/"
},
"@graph": [{
"@id": "ethstats:Uncle_0x5cd50096dbb856a6d1befa6de8f9c20decb299f375154427d90761dc0b101109",
"@type": "ethon:Uncle",
"ethon:blockCreationTime": "2015-07-30T15:26:58.000Z",
"ethon:blockHash": "0x5cd50096dbb856a6d1befa6de8f9c20decb299f375154427d90761dc0b101109",
"ethon:number": "1"
}]
}
序列化图形时,我将选项发送给 EasyRdf
'frame' => (object) [
'@context' => (object) [
'ethon' => 'http://ethon.consensys.net/',
'ethstats' => 'http://ethereum.ethstats.io/',
],
有没有办法为 rdf:type
/@type
属性发送 @set
选项?
最佳答案
是的!当framing ,另外传递 @context
选项:
"@context": {
...
"@type": {"@container": "@set"}
}
See it in use.
(如果由于某种原因无法在加载时正确显示,请单击Flattened 和(返回)Framed 选项卡。)
关于php - JSON-LD 总是将单个对象构建为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42783190/