投稿 资料上传 提问 搜索
您现在的位置是: 首页 > 问答 > 正文

.net json解析 求助各位大神!

[{"pid":"49","pgid":"4","pname":"全能虚拟主机400","pstock":"-1","pdes":"<p>功能说明:支持php5.2-PHP7.1 自由切换,独立管理面板,30天自动云端备份.数据库需单独购买,禁止大文件下载!</p>","phidden":"0","pprice":{"cprice":"420","onetime":"150","cycle":"12","pmothod":"1"},"pconfig":{"Connections":"0","WebSize":"400","MsSqlSize":"-1","MySqlSize":"-1","DomainSum":"0","productid":"19"},"pupgrade":"{}","psconfig":{"time_cycle":"0","nastock":"0","pricedes":"","trial_hours":"0","referralrate":"0","servicestatus":"-1","buylimit":"0"}},{"pid":"48","pgid":"4","pname":"全能虚拟主机300","pstock":"-1","pdes":"<p>功能说明:支持asp、.net2.0-net4.7 自由切换,独立控制面板,30天自动云端备份,数据库需单独购买,禁止大文件下载!</p>","phidden":"0","pprice":{"cprice":"320","onetime":"100","cycle":"12","pmothod":"1"},"pconfig":{"Connections":"0","WebSize":"300","MsSqlSize":"-1","MySqlSize":"-1","DomainSum":"0","productid":"19"},"pupgrade":"{}","psconfig":{"time_cycle":"0","nastock":"0","pricedes":"","trial_hours":"0","referralrate":"0","servicestatus":"-1","buylimit":"0"}},{"pid":"45","pgid":"4","pname":"全能虚拟主机200","pstock":"-1","pdes":"<p>功能说明:支持asp、.net2.0-net4.7 自由切换,独立控制面板,30天自动云端备份,数据库需单独购买,禁止大文件下载!</p>","phidden":"0","pprice":{"cprice":"220","onetime":"50","cycle":"12","pmothod":"1"},"pconfig":{"Connections":"0","WebSize":"200","MsSqlSize":"-1","MySqlSize":"-1","DomainSum":"0","productid":"19"},"pupgrade":"{}","psconfig":{"time_cycle":"0","nastock":"0","pricedes":"","trial_hours":"0","referralrate":"0","servicestatus":"-1","buylimit":"0"}},{"pid":"42","pgid":"4","pname":"全能虚拟主机100","pstock":"-1","pdes":"<p>功能说明:支持php5.2-PHP7.1 自由切换,独立管理面板,30天自动云端备份.数据库需单独购买,禁止大文件下载!</p>","phidden":"0","pprice":{"cprice":"120","onetime":"10","cycle":"12","pmothod":"1"},"pconfig":{"Connections":"0","WebSize":"100","MsSqlSize":"0","MySqlSize":"0","DomainSum":"0","productid":"19"},"pupgrade":"{}","psconfig":{"time_cycle":"0","nastock":"0","pricedes":"","trial_hours":"24","nodiscount":"1","referralrate":"0","servicestatus":"-1","buylimit":"0"}}]

想取到 pid 和 pconfig下面的WebSize  

问题回复
  1. 南笙一梦
    南笙一梦IT技术之家

    //简化的entity 对象
    class Dto{
    public string Pid{get;set;}
    public PConfig Pconfig{get;set;}
    }
    class PConfig{
    public int WebSize{get;set;}
    }

    var arr= Newtonsoft.Json.JsonConvert.DeserializeObject<Dto[]>("your json string");
    foreach(var item in arr){
    item.pid;
    item.pconfig.WebSize;
    }
    //自动生成的entity对象
    public class Dto
    {
    public string pid { get; set; }
    public string pgid { get; set; }
    public string pname { get; set; }
    public string pstock { get; set; }
    public string pdes { get; set; }
    public string phidden { get; set; }
    public Pprice pprice { get; set; }
    public Pconfig pconfig { get; set; }
    public string pupgrade { get; set; }
    public Psconfig psconfig { get; set; }
    }

    public class Pprice
    {
    public string cprice { get; set; }
    public string onetime { get; set; }
    public string cycle { get; set; }
    public string pmothod { get; set; }
    }

    public class Pconfig
    {
    public string Connections { get; set; }
    public string WebSize { get; set; }
    public string MsSqlSize { get; set; }
    public string MySqlSize { get; set; }
    public string DomainSum { get; set; }
    public string productid { get; set; }
    }

    public class Psconfig
    {
    public string time_cycle { get; set; }
    public string nastock { get; set; }
    public string pricedes { get; set; }
    public string trial_hours { get; set; }
    public string referralrate { get; set; }
    public string servicestatus { get; set; }
    public string buylimit { get; set; }
    public string nodiscount { get; set; }
    }


    回复