Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rapidjson: working code for reading document from file?

I need a working c++ code for reading document from file using rapidjson: https://code.google.com/p/rapidjson/

In the wiki it's yet undocumented, the examples unserialize only from std::string, I haven't a deep knowledge of templates.

I serialized my document into a text file and this is the code I wrote, but it doesn't compile:

#include "rapidjson/prettywriter.h" // for stringify JSON
#include "rapidjson/writer.h"   // for stringify JSON
#include "rapidjson/filestream.h"   // wrapper of C stream for prettywriter as output
[...]
std::ifstream myfile ("c:\\statdata.txt");
rapidjson::Document document;
document.ParseStream<0>(myfile);

the compilation error state: error: 'Document' is not a member of 'rapidjson'

I'm using Qt 4.8.1 with mingw and rapidjson v 0.1 (I already try with upgraded v 0.11 but the error remain)

like image 441
morde Avatar asked Aug 07 '13 15:08

morde


1 Answers

#include <rapidjson/document.h>
#include <rapidjson/istreamwrapper.h>
#include <fstream>

using namespace rapidjson; 
using namespace std;

ifstream ifs("test.json");
IStreamWrapper isw(ifs);
Document d;
d.ParseStream(isw);

Please read docs in http://rapidjson.org/md_doc_stream.html .

like image 74
Andrio Skur Avatar answered Sep 28 '22 12:09

Andrio Skur