static bool equalJson(Value &json1, Value &json2, Value &reference, bool a) {
for (Value::ConstMemberIterator itr = reference.MemberBegin(); itr <= reference.MemberEnd(); itr++) {
if (itr->value.GetType() == kArrayType) {
for (auto itr1 = itr->value.Begin(); itr1 != itr->value.End(); itr1++) {
// cout<<itr->name.GetString()<<endl;//Gets the keys or members that are arrays on the Top Level
switch (itr1->GetType()) {
case kObjectType:
for (auto itr = itr1->MemberBegin(); itr != itr1->MemberEnd(); itr++) {
// cout<<itr->name.GetString()<<endl;//Elements(keys) of the arrays
if (itr->value.GetType() == kArrayType) {
//cout<<itr->name.GetString()<<endl;//The keys inside the Top level array that are having sub arrays
Document doc;
//doc.CopyFrom(itr->name, doc.GetAllocator());
doc.CopyFrom(itr->value, doc.GetAllocator());
StringBuffer s;
Writer<StringBuffer> w(s);
doc.Accept(w);
cout << s.GetString() << endl;
// test::equalJson(json1,json2,doc,a);
}
}
}
}
}
I have a format something like this..
"object_array1": [
{"key": null },
{"key": null },
{"key": null }
]
What i have in the itr->value is
[
{"key": null },
{"key": null },
{"key": null }
]
I would like to have some thing like this.....in the Document doc;
{
"object_array1": [
{"key": null },
{"key": null },
{"key": null }
]
}
In order to acheive this i did try...
rapidjson::Value t_object(rapidjson::kObjectType);
t_object.CopyFrom(itr->value, doc.GetAllocator());
rapidjson::Value dir_name_key(itr->name.GetString(),
doc.GetAllocator());
doc.AddMember(dir_name_key, t_object, doc.GetAllocator());
but it's still an array
Your help will be highly appreciated. My reference json file:
{
"array": [
null
],
"boolean": null,
"null": null,
"object": {
"a": null,
"c": null,
"e": null
},
"number": null,
"deep_nested_array": [
{"object_array1": [
{"key": null },
{"key": null },
{"key": null }
]}
],
"object_array": [
{"key": null },
{"key": null },
{"key": null }
],
"string": null
}
Main aim is to use recursion to loop inside n number of nested arrays or objects( as the arrays in the json will be random) to get each key and utilize it. while recursing i need that valid format of data as I showed in the above description to be stored it in doc to pass in the function
static bool equalJson(Value &json1, Value &json2, Value &reference, bool a) {
while recursion:
equaljson(json1,json2,doc,a);
If you have better suggestion than this it will be a great help.Thank you