在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
System.Web.Extensions.dll中类JavaScriptSerializer可以帮助我们把C#对象转化为JSON字符串。 有一个Person类 1 public class Person 2 { 3 private string name; 4 5 public string Name 6 { 7 get { return name; } 8 set { name = value; } 9 } 10 private int age; 11 12 public int Age 13 { 14 get { return age; } 15 set { age = value; } 16 } 17 } 将List<Person>转化为JSON字符串 1 List<Person> persons = new List<Person>(); 2 persons.Add(new Person() {Name="zhangsan" ,Age=26}); 3 persons.Add(new Person() { Name = "lisi", Age = 26 }); 4 JavaScriptSerializer jss = new JavaScriptSerializer(); 5 string personsjson = jss.Serialize(persons); 转化JSON字符串 personsjson = "[{"Name":"zhangsan","Age":26},{"Name":"lisi","Age":26}]"
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论