简体   繁体   English

初始化JsonConvert.DeserializeObject

[英]Initialize JsonConvert.DeserializeObject

I have a really big chunk of JSON i'm deserializing with Newtonsoft.json 我要用Newtonsoft.json反序列化很大一部分JSON

Users.UserDataDict response = JsonConvert.DeserializeObject<Users.UserDataDict>(teststring);

I notice that the first time I call this method it's really slow (hundreds of milliseconds longer than it needs to be). 我注意到,第一次调用此方法的确很慢(比需要的时间长几百毫秒)。 So what I'm doing is calling it when the app starts on some large dummy data in so that when the user is interacting with the app it's not slow. 因此,我正在做的是在应用程序基于一些大的虚拟数据启动时调用它,以便在用户与应用程序进行交互时不会很慢。 Is there anyway I can just initialize it properly or increase it's buffer size or whatever needs done rather than calling it on start up on some really large data? 无论如何,我是否可以正确地对其进行初始化或增加其缓冲区大小或需要执行的任何操作,而不是在启动某些非常大的数据时调用它?

Seems that JsonConvert caches each type to be de-/serialized. 似乎JsonConvert缓存每种要反序列化的类型。 Based on that the first call to JsonConvert.SerializeObject / JsonConvert.DeserializeObject may take "longer". 基于此,对JsonConvert.SerializeObject / JsonConvert.DeserializeObject的首次调用可能需要“较长”的时间。 A more detailed answer can be found here . 这里可以找到更详细的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM