我可以在同一页面中使用多个JSON-LD组(使用Schema.org)吗?
如果我不能,如何将它们组合在一起?我对语法不太熟悉。
第1组:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "LocalBusiness",
"address": {
"@type": "PostalAddress",
"streetAddress": "3102 Highway 98",
"addressRegion": "FL",
"addressLocality": "Mexico Beach",
"postalCode": "45252",
"addressCountry": "US",
},
"geo": {
"@type": "GeoCoordinates",
"latitude": "40.75",
"longitude": "73.98"
},
"name": "Beachwalk Beachwear & Giftware",
"telephone": "850-648-4200",
"email": "admin@example.com",
"faxNumber": "860-562-4250",
}
</script>
第2组:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"url": "http://example.com",
"name": "My Domain Title",
"logo": "http://example.com/wp-content/uploads/2015/08/abc.jpg",
"contactPoint": [
{
"@type": "ContactPoint",
"telephone": "0192-39192130",
"contactType": "customer service"
},
{
"@type": "ContactPoint",
"telephone": "0182-239120398",
"contactType": "customer service"
}
],
"sameAs": [
"http://facebook.com/myfbaccount",
"http://twitter.com/mytwitteraccount"
]
}
</script>
答案 0 :(得分:11)
您可以在页面上拥有多个脚本块,也可以将它们组合在一个块中。将它们组合成单个块的最简单方法是使用@graph
关键字,如下所示:
<script type="application/ld+json">
{
"@graph": [
{ ... your first JSON-LD block ... },
{ ... your second JSON-LD block ... }
]
}
</script>
答案 1 :(得分:1)
根据规范(https://www.w3.org/TR/json-ld/#h3_advanced-context-usage),使用简单的上下文列表可以使用多个上下文:
[
{
"@context": "http://example.org/contexts/person.jsonld",
"name": "Manu Sporny",
"homepage": "http://manu.sporny.org/",
"depiction": "http://twitter.com/account/profile_image/manusporny"
},
{
"@context": "http://example.org/contexts/place.jsonld",
"name": "The Empire State Building",
"description": "The Empire State Building is a 102-story landmark in New York City.",
"geo": {
"latitude": "40.75",
"longitude": "73.98"
}
}
]