here is my code :
string json = JsonConvert.SerializeObject(stocksArticles,Formatting.Indented);
StreamWriter sw = new StreamWriter("Export\Stocks.json");
sw.Write(json);
it’s working fine but the json file is not complete it’s look like the StreamWriter stop before the end, this is the end of the file :
{ "Reference": "999840", "Stocks": { "S": 0.0 } }, { "
i dont understand why it’s stopping, i tried to define the buffersize for the StreamWriter but no effect.
2
Answers
you don’t need any stremwriter. just try this code
This is a common sign of not flushing/closing the stream (it is quite common for streams to maintain some buffer for performance reasons). You can do something like:
But far more correct approach is to use
using
which will dispose the resource correctly:Read more:
IDisposable