Schema.org JSON-LD reference

徘徊边缘 提交于 2019-11-26 11:53:57

You can identify a node by giving it a URI, specified in the @id keyword. This URI can be used to reference that node.

See the section "Node Identifiers" in the JSON-LD spec.

So your main event could get the URI http://example.com/2016-04-21#main-event:

<script type="application/ld+json">
{
  "@id": "http://example.com/2016-04-21#main-event",
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "MainEvent",
  "startDate": "2016-04-21T12:00"
}
</script>

and you could give this URI as the value for the sub event’s superEvent property:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "SubEvent",
  "startDate": "2016-04-21T12:00",
  "superEvent": { "@id": "http://example.com/2016-04-21#main-event" }
}
</script>

(You could of course give your sub event an @id, too. This would allow you and others to identify/reference this sub event.)

What you are looking for a node identifiers (see http://www.w3.org/TR/json-ld/#node-identifiers). You assign each entity a unique identifier in the form of a URL and use it in references:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@id": "http://event.com/#mainEvent",
  "@type": "Event",
  "name": "MainEvent",
  "startDate": "2016-04-21T12:00",
  "location": {
    ...
  }
}
</script>

Above you see I gave the event an @id. I appended a fragment (#mainEvent) because http://event.com/ would typically identify the page itself. You can then reference the event as follows:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Event",
  "name": "SubEvent",
  "startDate": "2016-04-21T12:00",
  "location": {
    ...
  }
  superEvent {
    "@id": "http://event.com/#mainEvent"
  }
}
</script>

Embedding as shown in your example works as well. In that case, you won't need the identifiers as it is clear what references what.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!