Warm tip: This article is reproduced from serverfault.com, please click

web standards-json-ld:建模自定义值的好方法

(web standards - json-ld: Good way to model custom values)

发布于 2016-12-12 16:37:07

我想获得一个很好的json-ld,它将schema.org/Product定义与一些自定义元素结合在一起。

我来自xsd背景,而json-ld的可扩展性似乎很难实现。

我从在Google(https://developers.google.com/search/docs/guides/search-gallery)上找到的产品的模板标记开始,然后尝试对其进行扩展(我想在其上添加mydomain:tags之类的东西) ),但我不确定如何执行此操作。

<script type="application/ld+json">
{
  "@context": ["http://schema.org/",
    {"mydomain": "http://mystuff.com/"}],
  "@type": "Product",
  "name": "Executive Anvil",
  "image": "http://www.example.com/anvil_executive.jpg",
  "description": "Sleeker than ACME's Classic Anvil, the Executive Anvil is perfect for the business traveler looking for something to drop from a height.",
  "mpn": "925872",
  "brand": {
    "@type": "Thing",
    "name": "ACME"
  },
  "aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": "4.4",
    "reviewCount": "89"
  },
  "offers": {
    "@type": "Offer",
    "priceCurrency": "USD",
    "price": "119.99",
    "priceValidUntil": "2020-11-05",
    "itemCondition": "http://schema.org/UsedCondition",
    "availability": "http://schema.org/InStock",
    "seller": {
      "@type": "Organization",
      "name": "Executive Objects"
    }
  },
  "mydomain:tags" : {}
}
</script>

关于我在这里做错了什么的任何线索将不胜感激。这可能是愚蠢的...

Questioner
CodingEdge
Viewed
0
unor 2016-12-18 19:06:07

你的JSON-LD似乎是正确的。你将示例19(紧凑型IRI示例29(高级上下文用法)组合使用

Google的结构化数据测试工具不是通用的JSON-LD验证器。它报告的错误主要是由于其搜索结果功能。他们的错误(“http://mystuff.com/tags对于类型为对象的对象,Google无法识别该属性Product。”)只是说这不是Google所知道的属性之一,这当然是正确的。

如果你想验证JSON-LD,而又不会因Google特定功能而出错,则可以使用http://json-ld.org/playground/