如何在 json-ld 文档中指定一对多和多对一关系?

How to specify 1 to many and many to 1 relations in json-ld document?

如何在 json-ld 中指定一对多和多对一关系。 例如:

{
  "@context" : {
    "@vocab" : "http://www.schema.org/",
    "@id" : "http://www.example.com/users/Joe",
    "name" : "name",
    "dob" : "birthDate",
    "age" : {
       "@id" : "http://www.example.com/users/Joe#age",
       "@type" : "Number"
        }
    "knows" : ["http://www.example.com/users/Jill", "http://www.example.com/users/James"]
    },
   "name" : "Joe",
   "age" : "24",
   "dob" : "12-Jun-2013"
}

这不会在 json-ld 游乐场中解析。 在 json-ld 或使用 Hydra 中指定此类关系的有效和最佳方法是什么?

您需要小心放入上下文中的内容以及放入文档正文中的内容。简单地说,上下文定义了到 URL 的映射,而主体包含实际数据。因此,您的示例应如下所示:

{
  "@context" : {
    "@vocab" : "http://www.schema.org/",
    "dob" : "birthDate",
    "age" : {
      "@id" : "http://www.example.com/users/Joe#age",
      "@type" : "Number"
    },
    "knows": { "@type": "@id" }
  },
  "@id" : "http://www.example.com/users/Joe",
  "name" : "Joe",
  "age" : "24",
  "dob" : "12-Jun-2013",
  "knows" : [
    "http://www.example.com/users/Jill",
    "http://www.example.com/users/James"
  ]
}