日期:2014-05-17 浏览次数:20488 次
protected void Page_Load(object sender, EventArgs e) {//构建json对象 string jsdata = "[ {id:'1',name:'0'}, {id:'6101',name:'北京市'}, {id:'6102',name:'天津市'}, {id:'6103',name:'上海市'}, {id:'6104',name:'重庆市'}, {id:'6105',name:'渭南市'}, {id:'6106',name:'延安市'}, {id:'6107',name:'汉中市'}, {id:'6108',name:'榆林市'}, {id:'6109',name:'安康市'}, {id:'6110',name:'商洛市'} ]";//将json数据转换成jsondata数组 jsondata[] jsda = new JavaScriptSerializer().Deserialize<jsondata[]>(jsdata);//获取数组中某个值 int str1 = jsda[1].id;}//类public class jsondata { public int id { get; set; } public string name { get; set; } }
protected void Page_Load(object sender, EventArgs e) {
//构建json对象
string jsdata = "[ {id:'1',name:'0'}, {id:'6101',name:'北京市'}, {id:'6102',name:'天津市'}, {id:'6103',name:'上海市'}, {id:'6104',name:'重庆市'}, {id:'6105',name:'渭南市'}, {id:'6106',name:'延安市'}, {id:'6107',name:'汉中市'}, {id:'6108',name:'榆林市'}, {id:'6109',name:'安康市'}, {id:'6110',name:'商洛市'} ]";
//将json数据转换成jsondata数组
jsondata[] jsda = new JavaScriptSerializer().Deserialize<jsondata[]>(jsdata);
//获取数组中某个值
int str1 = jsda[1].id;
}
//类
public class jsondata
{
public int id { get; set; }
public string name { get; set; }
}