我正在寻找通过json ld将结构数据脚本添加到ac#asp.net Web应用程序中。
这是我要添加的结构化数据脚本。由于与c#的@冲突,我遇到了运行时错误:The name 'context' does not exist in the current context
...这显然是由于@语法冲突。
解决这个问题的简单方法是什么?
<script type="application/ld+json"> { "@context": "http://schema.org", "@type": "LegalService", "image": "https://example.com.png", "@id": "https://example.com", "name": "Example Name", "description": "Example description.", "address": { "@type": "PostalAddress", "streetAddress": "Example Address", "addressLocality": "Example City", "addressRegion": "Example State", "postalCode": "Example Postal", "addressCountry": "Example Country" }, "url": "https://example.com", "telephone": "Example number", "sameAs": [ "example social account 1", "example social account 2" ] } </script>
因此,由于@scartag,解决此问题的方法是添加一个双@。
我也试图在脚本中添加一个循环,但出现运行时错误。我不确定这是否可能。它是针对将在CMS中生成的博客文章的。
见下文:
<script type="application/ld+json">
{
"@@context": "http://schema.org",
"@@type": "NewsArticle",
"mainEntityOfPage": {
"@@type": "WebPage",
"@@id": "https://google.com/article"
},
@foreach (var post in recent)
{
"headline": "Article headline",
"image": {
"@@type": "ImageObject",
"url": "https://google.com/thumbnail1.jpg",
"height": 800,
"width": 800
},
"datePublished": "2015-02-05T08:00:00+08:00",
"dateModified": "2015-02-05T09:20:00+08:00",
"author": {
"@@type": "Person",
"name": "John Doe"
},
"publisher": {
"@@type": "Organization",
"name": "Google",
"logo": {
"@@type": "ImageObject",
"url": "https://google.com/logo.jpg",
"width": 600,
"height": 60
}
},
"description": "A most wonderful article"
}
}
</script>
]
按照注释中的指示修复json(删除多余的)之后。
你可以逃脱的@
迹象
"@@context": "http://schema.org",
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句