1

How to get data from server in JSON format by using ASP.NET c#?

I know how to get data in JSON format using php but i'm trying to do the same but using c#.

3
  • same thing ....for getting data in JSON from server why you consider language? Commented Jan 9, 2016 at 14:04
  • I'd suggest you provide more details, e.g.are you trying to get the data from external server or do you want your own server to return the data in Json format? Commented Jan 9, 2016 at 14:05
  • Yes i want my own server to return data in JSON format Commented Jan 9, 2016 at 14:08

1 Answer 1

3

Consider following when you post your JSON from server side:

  1. data: JSON.stringify(person),

  2. contentType: "application/json"

On your client side:

  1. get the request body from HttpCurrent.Context.Request.InputStream.

  2. read the input stream and convert to string

  3. deserialize the json object

Do it like this::

string json;
using(var reader = new StreamReader(Request.InputStream)){
        json = reader.ReadToEnd();
    }
var person = Json.Decode(json);

Tutorial: http://www.mikesdotnetting.com/article/220/posting-data-with-jquery-ajax-in-asp-net-razor-web-pages

How to: Request Data Using the WebRequest Class

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

Comments

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.