我想看看是否有人可以发布一个如何动态创建JSON-LD以使用JQuery创建Google富卡的示例?如果有人能告诉我如何实现这一点,我真的很感激。
<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>
答案 0 :(得分: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>