at and followed quotation marks in a string (exiting & quot; or # 39; in View)

0

I'm trying to put the following text in a string, but I can not ... when there is no error in the double quotation marks of the at ... to getting crazy. Can anyone help me?

  

, {       "@type": "ListItem",       "position": 2,       "item": {       "@id": " link ",       "name": "description xyz",       "image": " link "       }       }

I'm trying something like this:

string TextoComplicado = ",{
"@type": "ListItem",
"position": 2,
"item": {
"@id": "http://www.enderecosite.com",
"name": "descrição xyz",
"image": "http://enderecosite/tumb-compartilhamento-facebook.jpg"
}
}";

This variable will be placed inside a script tag in my View:

<script type="application/ld+json"> @*Apenas detalhes do Imovél?*@
   @Model.TextoComplicado 
</script>

If I put '(single quotation marks) it is # 39; in place of the quotes

If I put \ "it's ecommercial print" instead of the quotation marks

How to solve this?

    
asked by anonymous 08.05.2018 / 19:48

2 answers

3

Simple quotes are for char, so the # 39 (ASCII Code).

And double quotation marks is for starting or ending a string. If you need to put one in the middle of the string, use an escape character: \ :

Example:

string x = """; //Erro

string y = "\""; //OK

Your case, it would look something like this:

string teste = " \"@type\": \"ListItem\"";

Edit:

Try to use System.Net.WebUtility.HtmlDecode(string); so that the string value is not displayed as Html code.

Example:

<script type="application/ld+json"> @*Apenas detalhes do Imovél?*@
   @System.Net.WebUtility.HtmlDecode(Model.TextoComplicado) 
</script>
    
08.05.2018 / 19:59
1

Do this:

        string TextoComplicado =
            ",{\r\n\"@type\": \"ListItem\",\r\n\"position\": 2,\r\n\"item\": {\r\n\"@id\": \"http://www.enderecosite.com\",\r\n\"name\": \"descrição xyz\",\r\n\"image\": \"http://enderecosite/tumb-compartilhamento-facebook.jpg\"\r\n}\r\n}";

Example here: link

    
08.05.2018 / 19:58