JSON ld structured data in asp c #

I want to add script structure data via json ld to C # asp.net web application.

Here is the structured data script I want to add. I am getting runtime errors due to @ C # conflict: The name 'context' does not exist in the current context

... this is obviously due to the @ syntax conflict.

What is an easy way to get around this?

<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>

      

So it looks like around this, thanks to @scartag, a double @ needs to be added.

I am also trying to add a loop inside the script, but I am getting runtime errors. I'm not sure if this is possible. This is for blog articles to be created in the CMS.

See below:

<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>

      

+3


source to share


1 answer


After fixing the json (removing redundant ]

) as pointed out in the comments.

You can get out of the sign @



"@@context": "http://schema.org",

      

+4


source







All Articles