From: Baptiste L. <bap...@gm...> - 2010-09-16 12:49:49
|
2010/9/15 Anath Bandhu Mandal <a_b...@ya...> > Hi > > I have been using the jsoncpp library, but having difficulties to > understand how to effectively read/write data using Json::Value objects. You > have give one example on http://jsoncpp.sourceforge.net/index.html, which > does not explore much of the classes on how are they should be used. For > example, I want to store about 4K of data with separator in one array, > but this array should be added for a million records for read/write. > However, I don't find an effective to way utilize this library due to > limited example code. > > Could you please provide some example code on how to effective utilize the > member functions for Json::Value, Json::Reader, and Json::Writer please? > You can look at the code of the jsontestrunner that is used for testing reader/writer (e.g. it reads a json file, and rewrite it in json, as well as a custom format). That being said, I don't think jsoncpp is a good choice of library for your use case: if I understood correctly (not sure what you mean by data with separator), you want to parse 4K * 1M values. Because the parser will load the whole json file in memory, a lot of memory is going to be wasted (I'm not even sure you will be able to fit the Json::Value tree in memory after conversion: 4K*1M=4*10**9 => means about 4GB of memory required if each value needed only 1 byte!). Writing should not be an issue as you can use the stream based writer that allow incremental writing to file. Baptiste. > Thanks, > AB Mandal > > |