找到你要的答案

Q:How do I send a json array to an ASP.NET server?

Q:我如何把一个JSON数组ASP.NET服务器吗?

I wrote this code to send some JSON to a server:

var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.brilliantit.ir/getDetail.aspx");
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "POST";

using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
    //string json = "{\"id\":\"ahbarres\"}";
    string json = "{\"id\":\""+label1.Text+"\"}";
    streamWriter.Write(json);
    streamWriter.Flush();
    streamWriter.Close();
}

String temp = "";
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
    var result = streamReader.ReadToEnd();
    temp = result.ToString();
}

But, I want to send a JSON array to a server. How can I do this?

我写了这个代码发送一些JSON到服务器:

var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.brilliantit.ir/getDetail.aspx");
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "POST";

using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
    //string json = "{\"id\":\"ahbarres\"}";
    string json = "{\"id\":\""+label1.Text+"\"}";
    streamWriter.Write(json);
    streamWriter.Flush();
    streamWriter.Close();
}

String temp = "";
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
    var result = streamReader.ReadToEnd();
    temp = result.ToString();
}

但是,我想送一个JSON数组服务器。我该怎么做?

c#  json  httpwebrequest