C# 如何在JSON文件中获取http请求的输出?

C# 如何在JSON文件中获取http请求的输出?,c#,asp.net,json,httprequest,C#,Asp.net,Json,Httprequest,我正在向url发出http get请求,我能够从该网页获取数据,但我无法将其存储为JSON格式,也无法解释数据并获取所需数据。我正在使用ASP.NET和C 这是我的CS文件的代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net

我正在向url发出http get请求,我能够从该网页获取数据,但我无法将其存储为JSON格式,也无法解释数据并获取所需数据。我正在使用ASP.NET和C

这是我的CS文件的代码:

    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";
            }
            }

        }
    }
我收到的输出截图是:


我希望在一个结构良好的JSON文件中获取输出,并且只希望其中包含站点名称、到达时间和离开时间。请告诉我怎么做?

看看这个项目:但是在使用网站所有者的数据之前,你需要询问他的信息

你请求的URL只是一个普通的网页,它不会返回JSON

为了做你想做的事,你需要勉强做出回应

使用HtmlAgilityPack查看此问题的示例:


是一个网页。。。它不返回json?为了“读取”json,您请求的URL必须返回json——这只是一个普通的网页。你需要刮除返回的html而不是你能告诉我如何读取我需要的数据,然后将其导出到JSON文件中吗?看看示例链接-我们不是来为你工作的@sikrigagan获取数据没有简单的规则。每一页都有自己的规则。你应该读一些文件。。。。。