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:

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:

  1. create object first
  2. read stream in loop, chunks, doing now
  3. fore every chunk you've read check if contains token (if comma "," found within)
  4. if no comma found - read chunk (maybe smaller 1 in case?)
  5. split pre - comma text (data.split(":");) , of reflection, or hardcoded loop, if dont need support every possible object, assign value property
  6. continue looping.

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -