php - JSON-LD 总是将单个对象构建为数组

标签 php arrays json json-ld easyrdf

有没有办法始终使用 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/

相关文章:

php - 如何修复 2 个 Web 客户端之间的字符串长度编码?

arrays - Cantor 的 ZigZag 函数 : Find the nth cell

jquery - 查找数组中的值 .inArray()

python - 比较 JSON 文档

javascript - 如何使用 JSON 为交互式 Backbone.js 应用程序提供支持

php - 使用 medoo 获取最后一个自动递增的 id

php - 如何使用 Zend DB 将值添加到表中的现有值

php - Magento安全交易支付方式需要持有支付选项

c - 将字符包读入数组,然后解析

Javascript - 解析 JSON,包括 int 作为对象