在JSON-LD中,是否可以为属性值定义URI映射?

时间:2014-10-29 15:03:06

标签: json-ld

假设我们有以下JSON:

{
  "@context":
  {
    "name": "http://schema.org/name",
    "status": "http://schema.org/status"
  },
  "name": "Manu Sporny",
  "status": "trollin'"
}

JSON-LD Playground

trollin'状态标识为URI:http://example.com/trolling。是否可以将上述示例中的trollin'关键字扩展为URI http://example.com/trolling

直接操纵上下文不起作用:

{
  "@context":
  {
    "name": "http://schema.org/name",
    "status": "http://schema.org/status",
    "trollin'": "http://example.com/trolling"
  },
  "name": "Manu Sporny",
  "status": "trollin'"
}

JSON Playground

强制status@id的类型也不会起作用,因为它会假定trollin'是相对URI。

{
  "@context":
  {
    "name": "http://schema.org/name",
    "status": {
      "@id": "http://schema.org/status",
      "@type": "@id"
    },
    "trollin'": "http://example.com/trolling"
  },
  "name": "Manu Sporny",
  "status": "trollin'"
}

JSON-LD Playground

1 个答案:

答案 0 :(得分:7)

是的,你可以这样做,你需要将状态类型设置为@vocab:

{
  "@context":
  {
    "name": "http://schema.org/name",
    "status": {
      "@id": "http://schema.org/status",
      "@type": "@vocab"
    },
    "trollin'": "http://example.com/trolling"
  },
  "name": "Manu Sporny",
  "status": "trollin'"
}

这里是游乐场的link