Appending child's Json::Value after appending parent's Json::Value does not change parent data, any...












0















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 ?










share|improve this question























  • Why do you use so much dynamic allocation and pointers? And did you expect that dereferencing one would result in a reference? It is not clear what you're trying to do.

    – Lightness Races in Orbit
    Jan 2 at 17:23











  • I was trying to convert excel-like data(multiple rows & cols) to json format. I had to add each col's data in a row into each json level. So i don't know how much parent json node will add child node(at the same col level).

    – Knowledge Drilling
    Jan 3 at 11:05













  • Anyway i implemented tree traversing mechanism from the bottom colum to root colum. So i don't need to change parent node anymore after adding child node.

    – Knowledge Drilling
    Jan 3 at 11:10











  • You neither need nor want any of this dynamic allocation. You're leaking memory like a sieve!

    – Lightness Races in Orbit
    Jan 3 at 11:17











  • Maybe i should delete all the appended data from Json tree after using it. Like deleting from child node to parent node, like recursively.

    – Knowledge Drilling
    Jan 4 at 14:34


















0















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 ?










share|improve this question























  • Why do you use so much dynamic allocation and pointers? And did you expect that dereferencing one would result in a reference? It is not clear what you're trying to do.

    – Lightness Races in Orbit
    Jan 2 at 17:23











  • I was trying to convert excel-like data(multiple rows & cols) to json format. I had to add each col's data in a row into each json level. So i don't know how much parent json node will add child node(at the same col level).

    – Knowledge Drilling
    Jan 3 at 11:05













  • Anyway i implemented tree traversing mechanism from the bottom colum to root colum. So i don't need to change parent node anymore after adding child node.

    – Knowledge Drilling
    Jan 3 at 11:10











  • You neither need nor want any of this dynamic allocation. You're leaking memory like a sieve!

    – Lightness Races in Orbit
    Jan 3 at 11:17











  • Maybe i should delete all the appended data from Json tree after using it. Like deleting from child node to parent node, like recursively.

    – Knowledge Drilling
    Jan 4 at 14:34
















0












0








0








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 ?










share|improve this question














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 ?







c++ jsoncpp






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 13:02









Knowledge DrillingKnowledge Drilling

3591415




3591415













  • Why do you use so much dynamic allocation and pointers? And did you expect that dereferencing one would result in a reference? It is not clear what you're trying to do.

    – Lightness Races in Orbit
    Jan 2 at 17:23











  • I was trying to convert excel-like data(multiple rows & cols) to json format. I had to add each col's data in a row into each json level. So i don't know how much parent json node will add child node(at the same col level).

    – Knowledge Drilling
    Jan 3 at 11:05













  • Anyway i implemented tree traversing mechanism from the bottom colum to root colum. So i don't need to change parent node anymore after adding child node.

    – Knowledge Drilling
    Jan 3 at 11:10











  • You neither need nor want any of this dynamic allocation. You're leaking memory like a sieve!

    – Lightness Races in Orbit
    Jan 3 at 11:17











  • Maybe i should delete all the appended data from Json tree after using it. Like deleting from child node to parent node, like recursively.

    – Knowledge Drilling
    Jan 4 at 14:34





















  • Why do you use so much dynamic allocation and pointers? And did you expect that dereferencing one would result in a reference? It is not clear what you're trying to do.

    – Lightness Races in Orbit
    Jan 2 at 17:23











  • I was trying to convert excel-like data(multiple rows & cols) to json format. I had to add each col's data in a row into each json level. So i don't know how much parent json node will add child node(at the same col level).

    – Knowledge Drilling
    Jan 3 at 11:05













  • Anyway i implemented tree traversing mechanism from the bottom colum to root colum. So i don't need to change parent node anymore after adding child node.

    – Knowledge Drilling
    Jan 3 at 11:10











  • You neither need nor want any of this dynamic allocation. You're leaking memory like a sieve!

    – Lightness Races in Orbit
    Jan 3 at 11:17











  • Maybe i should delete all the appended data from Json tree after using it. Like deleting from child node to parent node, like recursively.

    – Knowledge Drilling
    Jan 4 at 14:34



















Why do you use so much dynamic allocation and pointers? And did you expect that dereferencing one would result in a reference? It is not clear what you're trying to do.

– Lightness Races in Orbit
Jan 2 at 17:23





Why do you use so much dynamic allocation and pointers? And did you expect that dereferencing one would result in a reference? It is not clear what you're trying to do.

– Lightness Races in Orbit
Jan 2 at 17:23













I was trying to convert excel-like data(multiple rows & cols) to json format. I had to add each col's data in a row into each json level. So i don't know how much parent json node will add child node(at the same col level).

– Knowledge Drilling
Jan 3 at 11:05







I was trying to convert excel-like data(multiple rows & cols) to json format. I had to add each col's data in a row into each json level. So i don't know how much parent json node will add child node(at the same col level).

– Knowledge Drilling
Jan 3 at 11:05















Anyway i implemented tree traversing mechanism from the bottom colum to root colum. So i don't need to change parent node anymore after adding child node.

– Knowledge Drilling
Jan 3 at 11:10





Anyway i implemented tree traversing mechanism from the bottom colum to root colum. So i don't need to change parent node anymore after adding child node.

– Knowledge Drilling
Jan 3 at 11:10













You neither need nor want any of this dynamic allocation. You're leaking memory like a sieve!

– Lightness Races in Orbit
Jan 3 at 11:17





You neither need nor want any of this dynamic allocation. You're leaking memory like a sieve!

– Lightness Races in Orbit
Jan 3 at 11:17













Maybe i should delete all the appended data from Json tree after using it. Like deleting from child node to parent node, like recursively.

– Knowledge Drilling
Jan 4 at 14:34







Maybe i should delete all the appended data from Json tree after using it. Like deleting from child node to parent node, like recursively.

– Knowledge Drilling
Jan 4 at 14:34














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431646%2fappending-childs-jsonvalue-after-appending-parents-jsonvalue-does-not-chan%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431646%2fappending-childs-jsonvalue-after-appending-parents-jsonvalue-does-not-chan%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()