System.Net.WebRequest req = System.Net.WebRequest.Create(this.url_);
req.Method = "POST";
req.Timeout = 100000;
req.ContentType = "application/json";
byte[] sentData = Encoding.GetEncoding(1251).GetBytes(this.data_);
req.ContentLength = sentData.Length;
System.IO.Stream sendStream = req.GetRequestStream();
sendStream.Write(sentData, 0, sentData.Length);
sendStream.Close();
System.Net.WebResponse res = req.GetResponse();
System.IO.Stream ReceiveStream = res.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(ReceiveStream, Encoding.UTF8);
//Кодировка указывается в зависимости от кодировки ответа сервера
Char[] read = new Char[256];
string value = sr.ReadToEnd();
int count = sr.Read(read, 0, 256);
string Out = String.Empty;
while (count > 0)
{
String str = new String(read, 0, count);
string s = new string(read);
Out += str;
requestedData_ += s;
count = sr.Read(read, 0, 256);
}
return Out;
我需要像
这样的JSON格式{"object":{"1":"DEPO Name","244":"Lviv","245":"Lviv","246":"Lviv_2","247":"Lviv_2","248":"Lviv_2","249":"Lviv_2"},"errors":[],"fields":{}}
但它返回
"{\"object\":{\"1\":\"DEPO Name\",\"244\":\"Lviv\",\"245\":\"Lviv\",\"246\":\"Lviv_2\",\"247\":\"Lviv_2\",\"248\":\"Lviv_2\",\"249\":\"Lviv_2\"},\"errors\":[],\"fields\":{}}"
如何解决?
在这里你会看到 http://json2csharp.com/
我无法转换
PostTemplate value = new PostTemplate(this.url_ + url, data);
string result = value.GetData();
AddedDepoId returnId = JsonConvert.DeserializeObject<AddedDepoId>
(result);
我读过POST回答(是JSON格式)