wangxiaowei0303 / rapidjson

Automatically exported from code.google.com/p/rapidjson
MIT License
0 stars 0 forks source link

Serializing a document object #76

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am trying to port my code from jsoncpp to rapidjson. In jsoncpp, we could 
write,
Json::Value root;
Json::FastWriter writer;

root["a"] =p
root["b"] = q
root["c"] = r

and then string str = writer.write(root)

I need to perform a similar activity using rapidjson.
I searched around and found 
Document d;
StringBuffer sb;
Writer<StringBuffer> wr(sb);

document["a"] = p;
document["b"] = q;
document["c"] = r;

...

document.Accept(writer);
str = sb.GetString();

Is this approach correct? or Am I doing anything incorrect here??

Original issue reported on code.google.com by mymockem...@gmail.com on 5 Jun 2013 at 7:24

GoogleCodeExporter commented 9 years ago
First, you need to change document to object type:

d.SetObject();

Then you can call AddMember() functions:

d.AddMember("a", 10, d.GetAllocator());
...

Original comment by milo...@gmail.com on 18 Jun 2013 at 1:45