我正在使用Visual Studio c#中的asmx web服务。示例代码
WebRequest request = WebRequest.Create(WholeURL);
request.ContentType = "application/json; charset=utf-8";
request.Method = "POST";
request.ContentLength = postData.Length;
using (StreamWriter requester = new StreamWriter(request.GetRequestStream()))
{
requester.Write(postData);
requester.Close();
}
//Get the response
WebResponse response = request.GetResponse();
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.ok
string responseFromServer = reader.ReadToEnd();
如何从json响应中删除d
我的json回复是:{“d”: - 1} 我只需要-1。
由于
答案 0 :(得分:0)
我认为你只需要解析JSON,并在key =" d"中获取值。
使用JSON.NET
string json = @"{""key1"":""value1"",""key2"":""value2""}";
Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
Console.WriteLine(values.Count); // 2
Console.WriteLine(values["key1"]); // value1