服務器端已經用了很久的.Net core2.1,最近項目有些dll須要服務器、客戶端共享,想着把原來的客戶端從.Net Framework4.7.2升級到.Net Core3.1,順便也把服務器端升級成3.1。服務器
順手建了個項目,十分習慣的引用了 Newtonsoft.Json,而後發現包Newtonsoft.Json的前面出現了黃底三角形的黑色感嘆號
框架
什麼狀況!哦,原來目標框架缺省變成了.Net 5.0了,估計Newtonsoft.Json的版本有衝突。試了一下能用,可是看着黃色三角形難受。想着彷佛有個原裝的東東,試了一下,效果不錯,也比原來.Net Framework的寫法簡單了(沒有自成一體,基本跟newtonsoft同樣)。測試
手癢,簡單測試了一下pwa
static void Main(string[] args) { Stopwatch sw = Stopwatch.StartNew(); TestTextJson(); Console.WriteLine(sw.ElapsedMilliseconds); sw.Restart(); TestNewtonsoftJson(); Console.WriteLine(sw.ElapsedMilliseconds); Console.Read(); } static void TestTextJson() { for(int i=0;i<10000;i++) { var str = System.Text.Json.JsonSerializer.Serialize(new { a = 10, b = "abcd" }); } } static void TestNewtonsoftJson() { for (int i = 0; i < 10000; i++) { var str =Newtonsoft.Json.JsonConvert.SerializeObject(new { a = 10, b = "abcd" }); } }
結果:
原裝的耗時只有newtosoft的四分之一
code