Reputation: 1954
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#.
Upvotes: 1
Views: 1447
Reputation: 3211
Consider following when you post your JSON from server side:
data: JSON.stringify(person),
contentType: "application/json"
On your client side:
get the request body from HttpCurrent.Context.Request.InputStream.
read the input stream and convert to string
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
Upvotes: 3