首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

C# JSON 转换成 LIST对象,list对象替空值

2013-04-02 
C# JSON 转换成 LIST对象,list对象为空值我把JSON转换成LIST对象,但就是LIST里的数据为空,请高手指一下,代

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

热点排行