C# JSON 转换成 LIST对象,list对象为空值
我把JSON转换成LIST对象,但就是LIST里的数据为空,请高手指一下,代码如下:
JSON数据为:[{"xh":"0","xm":"AAA","xb":"男","csny":"1919-01-01"},{"xh":"1","xm":"AAA","xb":"男","csny":"1919-01-01"},{"xh":"2","xm":"AAA","xb":"男","csny":"1919-01-01"}]
System.IO.StreamReader streamReade = new System.IO.StreamReader(stream);
json = streamReade.ReadToEnd();
System.IO.MemoryStream ms = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(json));
List<jsonclass> lis = new List<jsoss>();
DataContractJsonSerializer ser = new DataContractJsonSerializer(lis.GetType());
lis = (List<jsonclass>) ser.ReadObject(ms);
context.Response.ContentType = "text/plain";
context.Response.Write(lis[0].xm); 为什么这里读出来的数成为空
[Serializable]
public class jsonclass:List<Object>
{
//[DataMember]
public string xh{get;set;}
//[DataMember]
public string xm{get;set;}
// [DataMember]
public string xb{get;set;}
// [DataMember]
public string csny{get;set;}
}
c#
json
list
------解决方案--------------------
//list类名
public class jsonclass
{
public string xh{get;set;}
public string xm{get;set;}
public string xb{get;set;}
public string csny{get;set;}
}
//调用时:json数据
//需要引用using System.Web.Script.Serialization;微软自带的
JavaScriptSerializer Serializer = new JavaScriptSerializer();
List<jsonclass> jsonclassList = Serializer.Deserialize<List<jsonclass>>(json);