标签:
转自http://blog.sina.com.cn/s/blog_84ee61a901018erd.html
使用微软自带的System.Web.Extensions.dll
该DLL文件一般存在于如下路径:c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Web.Extensions.dll
//将List集合转换为Json字符串, JavaScriptSerializer serializer = new JavaScriptSerializer(); List<Person> list = new List<Person>(); for (int i = 0; i < 10; i++) { Person p = new Person("张三" + i, "重庆" + i, "10" + i); list.Add(p); } MessageBox.Show(serializer.Serialize(list)); //将Json字符串转换为集合,Person为自己定义的实体类 string json = "[{‘Address‘:‘重庆0‘,‘Age‘:‘100‘,‘Name‘:‘张三0‘},{‘Address‘:‘重庆1‘,‘Age‘:‘101‘,‘Name‘:‘张三1‘}]"; JavaScriptSerializer serializer = new JavaScriptSerializer(); List<Person> list = serializer.Deserialize<List<Person>>(json);
2. MVC程序的话,可以直接用Json(sssss)
标签:
原文地址:http://my.oschina.net/shanlilaideyu/blog/519208