反序列化json C#

我有json如下:

{"data":[{"name":"123","pwd":123},{"name":"456","pwd":456},{"name":"789","pwd":789}],"duration":5309,"query":"myquery","timeout":300} 

使用http://json2csharp.com/我将其反序列化如下:

  namespace Test { public class Info { public string name{ get; set; } public string pwd{ get; set; } } public class Product { public Info[] data { get; set; } public int duration { get; set; } public string query { get; set; } public int timeout { get; set; } } //code here, function start etc. var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); Product myprod = JsonConvert.DeserializeObject(result); var results = myprod.data; } } 

结果的值是{Test.Info [0]},其中Test是我的命名空间名称。 我如何获得实际数据?

你的Info类应该是

 public class Info { public string name { get; set; } public int pwd { get; set; } } 

这应该工作

 var testJson = "{\"data\":[{\"name\":\"123\",\"pwd\":123},{\"name\":\"456\",\"pwd\":456},{\"name\":\"789\",\"pwd\":789}],\"duration\":5309,\"query\":\"myquery\",\"timeout\":300}"; var product = JsonConvert.DeserializeObject(testJson);