3

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

On the above URL, I get the output in a specific format foo({"1":"Jeff","2":"Mic","5":"Mark"}); using this small 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);

The full code of menu.aspx.cs is putup here. http://pastebin.com/dxbNmais

But this the output in html form on menu.aspx page. But my requirement is that the http answer must be json too. Please help in getting this JSON output. Not only that I I haven't tried JSON earlier but I am not too much a pro in ASP.NET.

2 Answers 2

2

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

That should do.

Sign up to request clarification or add additional context in comments.

Comments

1
Response.ContentType = "application/json";

4 Comments

Where do I have to write this?
Anywhere in the method, just do it right after Response.Write(outputText);
Just, that's it!? What's with all those scary web services which I find when I searched on Google ?
@Chrise: When I add this line `Response.ContentType = "application/json" to my method and then type the address of the page, it starts asking to save that menu.aspx page like I downloaded it. Here's the screenshot: i.imgur.com/4ZdTt.jpg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.