[英]Order and nesting of entities in JSON-LD Framing
给定一个包含不同类型实体的 JSON-LD,JSON-LD 框架能否允许控制这些实体在 output 中的顺序? 是否可以嵌套(使用@nest)一些实体来对它们进行分组?
给定来自操场的输入:
{
"@context": "https://www.w3.org/ns/activitystreams",
"@type": "Create",
"actor": {
"@type": "Person",
"@id": "acct:sally@example.org",
"name": "Sally"
},
"object": {
"@type": "Note",
"content": "This is a simple note"
},
"published": "2015-01-25T12:34:56Z"
}
我想实现这一点,并保证 Persons 将在 Activity 之后:
{
"@context": "https://www.w3.org/ns/activitystreams",
"@graph": [
{
"type": "Create",
"actor": "acct:sally@example.org",
"object": {
"type": "Note",
"content": "This is a simple note"
},
"published": "2015-01-25T12:34:56Z"
},
{
"id": "acct:sally@example.org",
"type": "Person",
"name": "Sally"
}
]
}
以下框架可以满足我的要求,但不提供订单保证:(我尝试使用["Person","Create"]
并且仍然在 Person 之前获得 Activity)
{
"@context": "https://www.w3.org/ns/activitystreams",
"type": ["Person", "Create"],
"actor": {
"@embed" : "@never",
"@omitDefault": true
}
}
而且,我可以将人员嵌套在persons
密钥中吗? 像这样:
{
"@context": "https://www.w3.org/ns/activitystreams",
"@graph": [
{
"type": "Create",
"actor": "acct:sally@example.org",
"object": {
"type": "Note",
"content": "This is a simple note"
},
"published": "2015-01-25T12:34:56Z"
},
"actors": [
{
"id": "acct:sally@example.org",
"type": "Person",
"name": "Sally"
}
]
]
}
通常,JSON 中的值排序仅限于数组值。 特别是,Map 结构中的键在 JSON 中没有任何固有顺序。 JSON-LD 算法通常会尝试按照看到的顺序处理密钥,但这不包括您关心的用例。
如果使用排序键的选项,键按字母顺序排列。
在您引用的情况下,“注释”实际上包含在“创建”下作为键的类型,因此您可能想要确保类型为“人”的 object 出现在类型为“创建”的 object 之后,但同样遗憾的是,即使值是有序的,也无法指定这一点。
您的最后一个示例实际上是无效标记,因为它是一个数组,但数组的第二个成员有一个键/值对。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.