Jtin
Jtin

Reputation: 44

how to display JSON output in asp.net webpage from sql database

i want to print following output by fetching data from sql in C#. I dont want to use asp.net web service. I just want to print JSON output on .aspx page.

{
    "dept_updates":
    [
        {
            "id":"11",
            "subject":"zzz",
            "utime":"Saturday 4th July 2015 05:20:29",
            "description":"zz","branch":"Computer Engineering",
            "flag":"http:\/\/www.emample.com\/login\/image\/5.jpg",
            "uploadedby":"JD"
        },
        {
            "id":"10",
            "subject":"hhh",
            "utime":"Monday 25th May 2015 02:48:46",
            "description":"hh","branch":"Information Technology",
            "flag":"http:\/\/www.example.com\/login\/image\/1\,
            "uploadedby":"JD"
         }

    ]
}

Upvotes: 2

Views: 992

Answers (1)

Thomas Koelle
Thomas Koelle

Reputation: 3742

I think the most straightforward way would be this:

<pre><%Response.Write(HttpUtility.HtmlEncode("foo")); %></pre>

(replace "foo" with JSON)

Notice how the pre should keep the spacing, and the HtmlCode should do that nothing bad comes out on screen.

Upvotes: 1

Related Questions