首页 > Web开发 > 详细

.Net Core 3.0原生Json解析器

时间:2019-09-07 10:36:57      阅读:84      评论:0      收藏:0      [点我收藏+]

微软官方博客中描述了为什么构造了全新的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>类,它类似于数组,但它不托管于堆上,因此提供了操作内存的高性能,这将对序列化和反序列化提供更高的性能。

同时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; }
    }

 

.Net Core 3.0原生Json解析器

原文:https://www.cnblogs.com/fanqisoft/p/11479193.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!