I am constructing json from tree data, but when i add node_level_3 from node_level_2 after adding node_level_2 from node_level_1, node_level_2 does not has information abour node_level_3. Here is my code.
node_level_1 = new Json::Value();
(*node_level_1)["data"] = first_value;
if (some_other_string != "")
{
node_level_2 = new Json::Value();
(*node_level_2)["data"] = some_other_string ;
(*node_level_1)["child"].append(*node_level_2);
}
if (another_string!= "")
{
node_level_3 = new Json::Value();
(*node_level_3) ["data"] = another_string;
(*node_level_2) ["child"].append(*node_level_3 );
}
I guess the problem is that 'Json::Value.append() function' only copy its data, not pointer or reference. So If i change data of node_level_2, it does not affect previously added node_level_2.
How can i solve this problem?? Should i have to traverse all the bottom nodes(level #3) of tree, and construct parent tree node (level #2) and finally add all the parent to root node(level #1)? Is this only solution With JsonCpp ?