Quotation marks exiting in incorrect JSON format!

Asked

Viewed 296 times

0

I’m creating a dictionary for JSON on Razor Pages, but the quotation marks ("), are coming out as "

_Layout.cshtml (UTF-8)

...
<body>
    ...
    <script type="application/ld+json">
        @JsonConvert.SerializeObject(new Dictionary<string, string>
        {
            { "@context", "http://schema.org" },
            { "@type", "Organization" },
            { "name", "Swenity" },
            { "url", "http://swenity.com" },
            { "logo", "/ui/lib/image/platform/swenity/basicPlatformWhite.png" }
        })
    </script>
    ...
</body>

Exit:

{&quot;@context&quot;:&quot;http://schema.org&quot;,&quot;@type&quot;:&quot;Organization&quot;,&quot;name&quot;:&quot;HAHA&quot;,&quot;url&quot;:&quot;http://example.com&quot;,&quot;logo&quot;:&quot;http://example.com/image.png&quot;}

How can I get them to come out in the correct format? How "

  • Give a little context. Where the information is being shown?

  • @LINQ updated, I’m showing in _Layout.cshtml

  • 1

    And where are you seeing the information? By the "inspect element" of the browser?

  • Yes, in Microsoft Edge I’m seeing (Inspect Element and Debugger = "Show Source"), in Google Chrome (Inspect and View Page Source)

  • My file is encoded as UTF-8

  • But what’s the point of this?

  • Representation only

Show 2 more comments

1 answer

0


I found the answer in an English OS question: https://stackoverflow.com/questions/9331195/json-net-serialize-c-sharp-object-to-json-issue

Using @Html.Raw() I can get the exit right without problems.

...
<body>
    ...
    <script type="application/ld+json">
        @Html.Raw(JsonConvert.SerializeObject(new Dictionary<string, string>
        {
            { "@context", "http://schema.org" },
            { "@type", "Organization" },
            { "name", "Swenity" },
            { "url", "http://swenity.com" },
            { "logo", "/ui/lib/image/platform/swenity/basicPlatformWhite.png" }
        }))
    </script>
    ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.