正确格式化JSON-LD标记

时间:2015-10-28 11:52:52

标签: schema.org json-ld

我试图在我的网页上添加一些JSON-LD标记。这是我写的

<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebPage",
"url": "http://www.example.com",
"name": "Title goes here"
}
</script>

^^这验证确定。非常基本:-)但是,我想为每个页面添加一些额外的描述性属性。

编辑:这是我试图放在一起的,没有验证:

<script type="application/ld+json">
   {
  "@context": "http://schema.org",
  "@type": "WebPage,
   "name": "Title goes here"
    "description": "Description goes here"
 "significantLink":{
"URL": "http://example.com/page"
"URL": "http://example.com/page2"
"URL": "http://example.com/page3"}
  "relatedLink":
{
"URL": "http://example.com/anotherpage"
"URL": "http://example.com/anotherpage2"
"URL": "http://example.com/anotherpage3"
}
}
</script>

什么可以帮助我更好地理解格式化将是一个扩展的示例,其中包含正确格式化的额外JSON-LD属性。有人可以解释一下如何纠正我的例子,包括以下属性吗?

&#39;描述&#39;
&#39;关键字&#39;
&#39; similarLink&#39;
&#39; relatedLink&#39;

如果您认为应该包含其他标记以获得良好的标记,请同时提及

1 个答案:

答案 0 :(得分:3)

您上次评论中的示例不是有效的JSON,因为您在某些属性值之后缺少逗号。我建议使用Google Structured Data Testing Tool来验证JSON和JSON-LD语法。

以下是每个媒体资源的单个项目示例:

<script type="application/ld+json">
{ 
  "@context": "http://schema.org", 
  "@type": "WebPage", 
  "name": "name of web page", 
  "description": "same content as Description meta tag",
  "keywords": "test, example",
  "significantLink": "http://example.com/page",
  "relatedLink": "http://example.com/anotherpage"
}
</script>

要添加多个signigicantLinkrelatedLink,只需创建属性数组即可。如果您不想将它们连接成一个字符串,也可以将keywords属性设为数组。

<script type="application/ld+json">
{ 
  "@context": "http://schema.org", 
  "@type": "WebPage", 
  "name": "name of web page", 
  "description": "same content as Description meta tag",
  "keywords": ["test", "example"],
  "significantLink": [
    "http://example.com/page",
    "http://example.com/page2"
  ],
  "relatedLink": [
    "http://example.com/anotherpage",
    "http://example.com/anotherpage2"
  ] 
}
</script>