读书人

C# JSON 转换成 LIST对象list对象替

发布时间: 2013-04-02 12:35:26 作者: rapoo

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);

读书人网 >.NET

热点推荐