c#解析json数据

来源:互联网 发布:上海数据港 待遇 编辑:程序博客网 时间:2024/05/22 08:01

要求传递过来的为一数组,dll从http://json.codeplex.com/下载

        using Newtonsoft.Json;          using Newtonsoft;          protected void Page_Load(object sender, EventArgs e)          {              if (!IsPostBack)              {                 string json = @"[{'phantom':true,'id':'20130717001','data':[{'MID':1019,'Name':'aaccccc','Des':'cc','Disable':'启用','Remark':'cccc'},{'MID':1029,'Name':'aaccccc','Des':'cc','Disable':'启用','Remark':'cccc'}]}]";                  List<Info> jobInfoList = JsonConvert.DeserializeObject<List<Info>>(json);                  foreach (Info jobInfo in jobInfoList)                  {                      Response.Write("UserName:" + jobInfo.id);                      foreach (data datainfo in jobInfo.data)                      {                          Response.Write("MID:" + datainfo.MID);                      }                    }              }          }            public class Info          {              public string phantom { get; set; }              public string id { get; set; }              public List<data> data { get; set; }          }          public class data          {              public int MID { get; set; }              public string Name { get; set; }              public string Des { get; set; }              public string Disable { get; set; }              public string Remark { get; set; }          }  


0 0
原创粉丝点击