0
I am running Schema for my page and need to convert the information to print it in JSON. However Newtonsoft.Json.JsonConvert.SerializeObject(schema); removes "@" from "@context" and "@type".
Like the code in Asp.NET is this:
#region schema
var schema = new SchemaProduct
{
@context = "http://schema.org",
@type = "Product",
productID = productId.ToString(),
description = funcoes.SanitizeHtml(produto.DescLonga, false),
name = produto.Titulo,
image = fotos,
url = Request.Url.ToString(),
offers = new SchemaOffer
{
@type = "Offer",
areaServed = string.Format("{0}/{1}", produto.Localizacao, produto.Estado),
category = string.Format("{0} > {1} > {2}", cat1.Nome, cat2.Nome, cat3.Nome),
price = string.Format("{0:C}/{1}", produto.ValorVista, produto.Unidade)
}
};
var text = "<script type='application/ld+json'>";
text += Newtonsoft.Json.JsonConvert.SerializeObject(schema);
text += "</script>";
ltSchema.Text = text;
#endregion
How it is printed:
<script type='application/ld+json'>
{
"productID":".....",
"offers":
{
"type":"......",
"price":".....",
"areaServed":"....",
"category":"....."
},
"context":"http://schema.org",
"type":".....","url":".......",
"image":["....."]
}
</script>