0

如何在 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 中指定此类关系的有效和最佳方法是什么?

4

1 回答 1

1

您需要小心您放入上下文中的内容以及放入文档正文中的内容。简单地说,上下文定义了到 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"
  ]
}
于 2015-06-24T20:53:20.537 回答