首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSON-LD总是将单个对象帧化为数组

JSON-LD总是将单个对象帧化为数组
EN

Stack Overflow用户
提问于 2017-03-14 18:16:20
回答 1查看 181关注 0票数 3

有没有一种方法可以使用EasyRdf始终强制单个对象到数组中?

如果有多个值作为rdf:type,我会得到一个类似下面这样的数组。注意:@type属性是一个数组。

代码语言:javascript
复制
{
    "@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属性不是数组。

代码语言:javascript
复制
{
    "@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

代码语言:javascript
复制
'frame' => (object) [
    '@context' => (object) [
        'ethon' => 'http://ethon.consensys.net/',
        'ethstats' => 'http://ethereum.ethstats.io/',
],

有没有办法为rdf:type / @type属性发送@set选项?

EN

回答 1

Stack Overflow用户

发布于 2020-12-15 21:54:57

是!如果为framing,则额外传递@context选项:

代码语言:javascript
复制
"@context": {
    ...
    "@type": {"@container": "@set"}
}

See it in use.

(如果由于某种原因在加载时不能正确显示,请单击扁平化和(返回到)边框选项卡。)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42783190

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档