专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > .NET相关

C# JSON 转换成 LIST对象,list对象为空值解决方法

发布时间:2011-06-26 21:02:50 文章来源:www.iduyao.cn 采编人员:星星草
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;}

   
}
------解决方案--------------------


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

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: