On Wed, Apr 15, 2015 at 9:36 AM André Somers <[email protected]> wrote:
> Mathieu Slabbinck schreef op 15-4-2015 om 16:17:
> > Hi,
> >
> > I'm using Qt5 to write json objects to a file.
> > The json structure contains one array with x data elements, like:
> >
> > {
> > "datapointsarray": [
> > {
> > "datapoint":"1",
> > "datapoint":"2",
> > ...
> > }
> > ]
> > }
> > Each x seconds, a "datapoint" should be added.
> >
> > The dilemma I'm in is, how can I tell the json writer to "append" to a
> > current json file without loading the whole file back in memory (eg
> > read json from file->edit in Qt->write back to file). Because, after a
> > while, I suppose the file will get quite large.
> >
> I don't think JSON is particulary suitable for this kind of application
> (and neither is XML). The problem is that you cannot just append to the
> end of the file, and that is really what you want. You could fake that
> by abusing you knowledge of the structure of the document to write your
> datapoint directly and then write out the closing stuff (that is "}]}"
> in your example) yourself as well. Not nice, but it works (at least with
> the simple structure you have now).
>
I had a similar problem. I ended up treating the "JSON object" like a
std::deque. I would break up the data into multiple JSON documents so that
appending to the end only required reading a subset of the content. But
when you write that amount of code to do it, you might want to start
looking at a database instead.
_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest