C# json处理

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using Newtonsoft.Json;


public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {


        String url = "http://www.ltweishi.com/c.ashx?m=ver&company=ltcws";
        string result = getURLResponse(url);
        StringReader sr = new StringReader(result);
        JsonReader jr = new JsonReader(sr);
        while (jr.Read())
        {
            Response.Write(jr.Value + "\t\t");
        }


        Response.Write("<br />"+ result);


    }


    String getURLResponse(String url) 
    {
        System.Net.WebRequest myWebRequest = System.Net.WebRequest.Create(url);
        System.Net.HttpWebResponse myWebResponse = (System.Net.HttpWebResponse)myWebRequest.GetResponse();
        System.IO.StreamReader reader = new System.IO.StreamReader(myWebResponse.GetResponseStream(), System.Text.Encoding.UTF8);
        String result = reader.ReadToEnd();
        reader.Close();
        reader.Dispose();
        return result;
    }
}

你可能感兴趣的:(C# json处理)