c# - Streaming large list of data as JSON format using Json.net -


Using the MVC model, I would like to write a JasonResult which will stream instead of converting Jason String Client into client Once in Jason String and then streaming back to the client, I have actions that need to be very large (more than 3,00,000 records) in the form of Jason Transfer and I think the basic Implementation of Eason Reshlt is not scaled.

I am using JSNNETNet, I am thinking that there is a way to convert it to the Jason String partition, it is being converted.

  // Existing Implementation: Answer Newsletter response.End (); // I know that I can use JasonSylerizers instead of NewtonSoft. Jason Jason Surgery Serial = New NewtonSoft Jason Jason Surgery (); Serializer.Serialize (textWriter, data);   

Although I'm not sure how I can get the sections written in textWriter and write in response and call reponse.Flush until 300,000 records in Jason Do not change

Is this possible?

Assume that your final output is a JSON array and each "Chuck" is an item in that array , You can try something like the following JsonStreamingResult class. It uses a JsonTextWriter to write JSON in the output stream, and use a Jobbject to sort each item individually before writing to the author You can JsonStreamingResult a IEnumerable implementation that can read items from your data source individually, so that you can not do them all in memory at once. I have not tested this on a large scale, but it should take you in the right direction.

  public class JsonStreamingResult: ActionResult {Private IEnumerable itemsToSerialize; Public JsonStreamingResult (IEnumerable itemsToSerialize) {this.itemsToSerialize = itemsToSerialize; } Public Override Zero ExecuteResult (Controller Reference Reference) {var response = context. HttpContext.Response; reaction. Contact Type = "App / Jason"; Response.ContentEncoding = encoding.UTF8; JsonSerializer serializer = new JsonSerializer (); (Using JedstenTextWriter Writer = New JasontextWitter (SW)) (Author; White Startre) (Using serial SW = new streamer (feedback output stream)); Foreign object (toorize items in object items) {Jobic obj = Jobbject.FromObject (item, serializer); Obj.WriteTo (author); Writer.flush (); } Author. WrititeEndArray (); }}}    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -