JavaScriptSerializer进行JSON序列化,得到字符串
1.引用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace ConsoleApplication3 { class Program { class Fruit { public string Color { get; set; } public string Size { get; set; } public string Name { get; set; } public DateTime CreateTime { get; set; } } static void Main(string[] args) { List<Fruit> f = new List<Fruit>(); for (int i = 0; i < 5; i++) { Fruit c = new Fruit(); c.Color = "red"; c.Size = "12"; c.Name = "Apple_" + i; c.CreateTime = DateTime.Now; f.Add(c); } System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer(); System.Text.StringBuilder dataString = new StringBuilder(); jss.Serialize(f, dataString); string ccx = "\"" + @"\\/Date\((\d{1,})\)\\/" + "\""; string res = Regex.Replace(dataString.ToString(), ccx, "new Date($1)", RegexOptions.IgnoreCase); Console.WriteLine(res); } } }