转自
使用微软自带的System.Web.Extensions.dll
该DLL文件一般存在于如下路径:c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Web.Extensions.dll
//将List集合转换为Json字符串,JavaScriptSerializer serializer = new JavaScriptSerializer();Listlist = new List ();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 list = serializer.Deserialize
>(json);
2. MVC程序的话,可以直接用Json(sssss)