0

我想看看是否有人可以发布一个如何动态创建 JSON-LD 以使用 JQuery 创建谷歌富卡的示例?如果有人可以向我展示如何实现此功能的示例,我将不胜感激。

    <script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [{
    "@type": "ListItem",
    "position": 1,
    "item": {
      "@id": "https://www.avenue.com/",
      "name": "Home",
    }
  },{
    "@type": "ListItem",
    "position": 2,
    "item": {
      "@id": "https://www.avenue.com/en_US/plus-size-clothing/dresses/",
      "name": "Plus Size Dresses",
    }
  }]
}
</script>
4

1 回答 1

1

您不应该使用 jQuery 创建它。您应该按照以下示例将其放入 isml 模板中:

<script type="application/ld+json">
    <isprint value="${JSON.stringify(ldJSON)}" encoding="off"/>
</script>

或者如果你想硬编码结构:

<script type="application/ld+json">
    {
        "@context": "${context}",
        "@type": "${type}",
        "url": "<isprint value="${varURL}" />",
        "potentialAction": {
            "@type": "${searchType}",
            "target": "<isprint value="${theTarget}" />{search_term_string}",
            "query-input": "required name=search_term_string"
        }
    }
</script>
于 2018-05-16T11:08:23.613 回答