I am trying to create a json document using rapidjson but I don't know how I can replicate part of the following document, in particular the nested object starting with "allocations", for the others elements I do
Value valObjectString(kStringType);
valObjectString.SetString("string");
doc.AddMember("string", valObjectString, doc.GetAllocator());
But what about "allocation" and "url" ?
{
"string1": "string",
"string2": "string",
"string3": "string",
"string4": "string",
"string5": "string",
"allocations": [
{
"allocation": "string",
"url": "string"
}
]
}
you can do like this
Value valObjectString(kStringType);
valObjectString.SetString("string");
doc.AddMember("string", valObjectString, doc.GetAllocator());
Value array(kArrayType);
Value tmp;
tmp.SetObject();
tmp.AddMember("allocation", "string", doc.GetAllocator());
tmp.AddMember("url", "string", doc.GetAllocator());
array.PushBack(tmp, doc.GetAllocator());
doc.AddMember("allocations", array, doc.GetAllocator());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With