因为我的android中的是fastjson,所有准备在服务端也用fastjson,但可惜的是c#的fastjson不是阿里的
https://www.codeproject.com/Articles/159450/fastJSON(这是c#版的fastjson作者博客地址)
先上代码,User是一个类
List<User> users = new List<User>();
string json = "";
for (int a=0;a<1000000;a++) {
User user = new User();
user.Address = "我是地址";
user.Contacter = "我是紧急联系人";
user.ContactPhone = "我是紧急联系人联系方式";
user.EdiTime = DateTime.Now;
user.Email = "我是邮箱";
user.HeadThumbUrl = "我是头像缩略图路径";
user.HeadUrl = "我是头像路径";
user.ID =a;
user.IdCard = "我是身份证";
user.LoginId = "我是登录账号";
user.NFCID = "我是NFCID";
user.Note = "我是备注";
user.Number = "我是编号";
user.Password = "我是密码";
user.Phone = "我是手机号";
user.ReTime = DateTime.Now;
user.RFID = "我是RFID";
user.Role = 1;
users.Add(user);
}
DateTime begin, end;
//Console.WriteLine("fastjson序列化开始:" + (begin = DateTime.Now));
//json = fastJSON.JSON.ToJSON(users);
//Console.WriteLine("fastjson序列化结束:" + (end = DateTime.Now));
//Console.WriteLine("用时" + (end - begin).TotalSeconds);
//Console.WriteLine("fastjson反序列化开始:" + (begin = DateTime.Now));
//users = fastJSON.JSON.ToObject<List<User>>(json);
//Console.WriteLine("fastjson反序列化开始结束:" + (end = DateTime.Now));
//Console.WriteLine("用时" + (end - begin).TotalSeconds);
Console.WriteLine("JsonConvert序列化开始:" + (begin = DateTime.Now));
json = JsonConvert.SerializeObject(users);
Console.WriteLine("JsonConvert序列化结束:" + (end = DateTime.Now));
Console.WriteLine("用时" + (end - begin).TotalSeconds);
Console.WriteLine("JsonConvert序列反化开始:" + (begin = DateTime.Now));
users = JsonConvert.DeserializeObject<List<User>>(json);
Console.WriteLine("JsonConvert反序列化结束:" + (end = DateTime.Now));
Console.WriteLine("用时" + (end - begin).TotalSeconds);
Console.ReadKey();
测试结果:
下图为fastjson
下图为Newtonsoft.Json
结论:Newtonsoft.Json效率接近是fastjson的两倍,所以我弃用了fastjson。。。。。。。。。。。