我想知道如何使用JSON-LD(由Google提供的recommended和Schema.org规范来表示重复属性。例如,我们应该如何用 N Article
s(N> 1)个Comment
来表示?
像下面的示例一样,允许将数组作为comment
值。 Google testing tool喜欢它似乎是。
但是可以使用 flat @graph
表示法代替吗?怎么样?我必须开发一个站点,并且这种表示形式可能更易于实现。
我想两者都允许吗?那怎么选择呢?
我的例子:
<script type="application/ld+json">
{
"@context" : "http:\/\/schema.org",
"@type" : "Article",
"url" : "https:\/\/exemple.com/article?id=1234",
"author" :{"@type" : "Person","name" : "Didier"},
"image" : "https:\/\/exemple.com/article.jpg",
"mainEntityOfPage" : "https:\/\/exemple.com",
"dateModified" : "2018-06-14T19:50:02+02:00",
"datePublished" : "2018-06-14T19:50:02+02:00",
"publisher" : {"@type" : "Organization","name" : "exemple.com", "logo" : {"@type" : "ImageObject", "url" : "https:\/\/exemple.com\/logo.png"}},
"headline" : "my article",
"text" : "blah blah",
"commentCount" : 2,
"comment" : [{
"author" : {"@type" : "Person", "name" : "Didier"},
"text" : "comment first!!",
"dateCreated" : "2018-06-14T21:40:00+02:00"
},{
"author" : {"@type" : "Person", "name" : "Robert"},
"text" : "second comment",
"dateCreated" : "2018-06-14T23:23:00+02:00"
}]
}
</script>
答案 0 :(得分:4)
最简单(也是最受支持)的方法是提供一个数组作为值,就像您的代码段一样:
"comment": [
{"@type": "Comment"},
{"@type": "Comment"}
]
如果要使用多个顶级项目(with @graph
or other options),则需要一种方式来传达这些顶级Comment
项目是Article
的注释。
With @id
,您可以为每个项目指定一个URI并将其作为属性值引用,而不是嵌套该项目:
{
"@context": "http://schema.org",
"@graph": [
{
"@type": "Article",
"@id": "/articles/foobar",
"comment": [
{"@id": "/articles/foobar#comment-1"},
{"@id": "/articles/foobar#comment-2"}
]
},
{
"@type": "Comment",
"@id": "/articles/foobar#comment-1"
},
{
"@type": "Comment",
"@id": "/articles/foobar#comment-2"
}
]
}
除了在Article
下列出注释URI,还可以在每个Article
,with @reverse
中引用Comment
:
{
"@context": "http://schema.org",
"@graph": [
{
"@type": "Article",
"@id": "/articles/foobar"
},
{
"@type": "Comment",
"@id": "/articles/foobar#comment-1",
"@reverse": {"comment": {"@id": "/articles/foobar"}}
},
{
"@type": "Comment",
"@id": "/articles/foobar#comment-2",
"@reverse": {"comment": {"@id": "/articles/foobar"}}
}
]
}