c# - How to deserialize a very large JSON data directly from stream instead of loading the entire json at once -
possible duplicate:
incremental json parsing in c#
the following questions related don't address (at least directly) problem i'm trying solve:
- load json data stream text file objects c#
- deserializing json .net object using newtonsoft (or linq json maybe?)
i trying deserialize potentially large json data using json.net. instead of loading entire file memory , parse json using jobject.parse(jsonfullstring), wish read stream token token , construct object graph. appreciate suggestion on how implement deserialization stream.
note: intent replace following code better implementation
string jsondata = string.empty; byte[] buffer = new byte[16 * 1024]; using (memorystream ms = new memorystream()) { int read; while ((read = stream.read(buffer, 0, buffer.length)) > 0) { ms.write(buffer, 0, read); } jsondata = asciiencoding.ascii.getstring(ms.toarray()); } jobject jobject = jobject.parse(jsondata); var entities = e in jobject.root select e;
nice idea!
think can following:
- create object first
- read stream in loop, chunks, doing now
- fore every chunk you've read check if contains token (if comma "," found within)
- if no comma found - read chunk (maybe smaller 1 in case?)
- split pre - comma text (data.split(":");) , of reflection, or hardcoded loop, if dont need support every possible object, assign value property
- continue looping.
Comments
Post a Comment