json.net - Reading Large JSON file into variable in C#.net -
i trying parse json files , insert sql db.my parser worked fine long files small (less 5 mb).
i getting "out of memory exception" when trying read large(> 5mb) files.
if (system.io.directory.exists(jsonfilepath)) { string[] files = system.io.directory.getfiles(jsonfilepath); foreach (string s in files) { var jsonstring = file.readalltext(s); filename = system.io.path.getfilename(s); parsejson(jsonstring, filename); } }
i tried jsonreader approach, no luck on getting entire json string or variable.please advise.
use 64 bit, check rredcat's answer on similar question:
newtonsoft.json - out of memory exception while deserializing big object
newtonsoft jason performance tips
read article david cox tokenizing:
"the basic approach use jsontextreader object, part of json.net library. jsontextreader reads json file 1 token @ time. it, therefore, avoids overhead of reading entire file string. tokens read file, objects created , pushed onto , off of stack. when end of file reached, top of stack contains 1 object — top of big tree of objects corresponding objects in original json file"
Comments
Post a Comment