C# 解析json类型字符串

public static string json = @"[
{'pID':'0011','pName':'北京', 'pCity':[{'cID':'1100','cName':'北京'}]}
,{'pID':'0012','pName':'天津','pCity':[{'cID':'1200','cName':'天津'}]}
,{'pID':'0013','pName':'河北','pCity':[{'cID':'1301','cName':'石家庄'}
,{'cID':'1302','cName':'保定'}
,{'cID':'1303','cName':'沧州'}
,{'cID':'1304','cName':'承德'}
,{'cID':'1305','cName':'邯郸'}
,{'cID':'1306','cName':'衡水'}
,{'cID':'1307','cName':'廊坊'}
,{'cID':'1308','cName':'秦皇岛'}
,{'cID':'1309','cName':'唐山'}
,{'cID':'1310','cName':'邢台'}
,{'cID':'1311','cName':'张家口'}]}

]

 

 

public static List<Privince> getAllArea()
{
       return new JavaScriptSerializer().Deserialize<List<Privince>>(json);
}

 

//id要对应

public class Privince
{
     public int pID { get; set; }
     public string pName { get; set; }
  public List<City> pCity { get; set; }
}
public class City
{
  public int cID { get; set; }
  public string cName { get; set; }
}

posted @ 2014-10-27 17:26  小菜鸟飞飞  阅读(266)  评论(0编辑  收藏  举报