.Net Core 3.0原生Json解析器


微软官方博客中描述了为什么构造了全新的Json解析器而不是继续使用行业准则Json.Net

微软博客地址:https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-apis/

在官方的Github中,也有关于此问题的详细描述:https://github.com/dotnet/corefx/issues/33115

简单说明就是.Net Core有一个Span<T>类,它类似于数组,但它不托管于堆上,因此提供了操作内存的高性能,这将对序列化和反序列化提供更高的性能。

官方API完整介绍https://docs.microsoft.com/zh-cn/dotnet/api/system.text.json?view=netcore-3.0

同时UTF-8和UTF-16也是微软考虑的一个点。

开始详细了解一下吧:

  

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            string person = "[{\"name\":\"fanqi\",\"age\":25,\"phone\":[\"10086\",\"10010\"]},{\"name\":\"zhangrong\",\"age\":24,\"phone\":[\"10000\",\"10010\"]}]";
            List<Person> personList = JsonSerializer.Deserialize<List<Person>>(person);
            string json = JsonSerializer.Serialize(personList, personList.GetType());
            JsonDocument document = JsonDocument.Parse(person);
            Console.ReadKey();

        }
    }
    class Person
    {
        public string name { get; set; }
        public int? age { get; set; }
        public List<string> phone { get; set; }
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM