I am reading a json file which contains large data and deserializing it into object. I am trying to increase the performance by reading the bytes and deserialize it. But when I searched it says I have to convert it to string to deserialize it. Is there any way to deserialize directly without converting into string.
Below is what I have done.
byte[] bytesArray = File.ReadAllBytes(path); var bytesAsString = Encoding.ASCII.GetString(bytesArray); object person = JsonConvert.DeserializeObject<List<PersonList>>(bytesAsString); I want to remove the second line and go directly to the next step, ie, skip converting to string.
using (StreamReader file = File.OpenText(path)) { JsonSerializer jsonSerializer = new JsonSerializer { NullValueHandling = NullValueHandling.Ignore }; object person = (object)jsonSerializer.Deserialize(file, typeof(List<PersonList>)); } Above code I read the whole file and convert it into object. My aim of reading bytes is to increase the performance of this code.