gpt4 book ai didi

c# - asp c# 中的结构化数据 JSON ld

转载 作者:太空狗 更新时间:2023-10-30 01:00:46 25 4
gpt4 key购买 nike

我希望通过 json ld 将结构数据脚本添加到 c# asp.net web 应用程序。

这是我要添加的结构化数据脚本。由于与 c# 的 @ 冲突,我收到运行时错误:当前上下文中不存在名称“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",

关于c# - asp c# 中的结构化数据 JSON ld,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43622479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com