Json.net has asynchronous functions for converting an object to json:
jsn = await JsonConvert.DeserializeObjectAsync<T>
But when I want to write an object to a json file, it seems to me better to work directly with the Stream file.
So, I think it should be something like this:
var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite); using (IOutputStream outputStream = fileStream.GetOutputStreamAt(0)) { using (StreamWriter sw = new StreamWriter(fileStream.AsStreamForWrite())) { using (JsonWriter jw = new JsonTextWriter(sw)) { jw.Formatting = Formatting.Indented; JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(jw, obj); } }
But on the JsonSerzializer object, I cannot find async methods. Also, I think I / O operations should not fit in their own thread.
What is the recommended approach?
source share