JSON output from page

I am developing an ASP.NET site in which, based on a certain logic, I get output in a specific format on http://localhost/menu.aspx?callback=example

In the above url, I get output in a specific format foo({"1":"Jeff","2":"Mic","5":"Mark"});with this little code.

outputText += Convert.ToString(k.GetValue(0));
for (Int32 i = 1; i < k.Length; i++)
{
    outputText += "," + Convert.ToString(k.GetValue(i));
}
//
outputText += "}" +");";

Response.Write(outputText);

Here is the full code menu.aspx.cs. http://pastebin.com/dxbNmais

But this is the html output on the page menu.aspx. But my requirement is that the HTTP response should be json too. Please help in getting this JSON output. Not only have I not tried JSON before, but I'm not too professional in ASP.NET.

+3
source share
2 answers
Response.ContentType = "application/json";
+1
source

add Response.End();afterResponse.Write(..

That should do.

+2
source

Source: https://habr.com/ru/post/1786991/


All Articles