I am making a http get request to a url and I am able to get data from that web page but I am not able to store it in JSON format and also not able to interpret data and get the required data.I am using ASP.NET and C# for it.
This is code for my CS file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using Newtonsoft.Json;
namespace httprequest_web
{
public partial class req : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
string baseu = "http://railenquiry.in/runningstatus/";
string url = string.Concat(baseu, TextBox1.Text);
var request = WebRequest.Create(url);
string text;
var response = (HttpWebResponse)request.GetResponse();
using (var sr = new StreamReader(response.GetResponseStream()))
{
request.ContentType = "application/json; charset=utf-8";
text = sr.ReadToEnd();
}
Label1.Text = text;
}
catch
{
Label1.Text = "No Data Found";
}
}
}
}
and screenshot of output I am receiving is:
I want to take output in a well structured JSON file and only want name of station, time of arrival and time of departure in it. Please tell me how to do it?