Reputation: 65
I am trying to change values in my jsoncpp object. I found multiple solutions for jsoncpp array, but so far none for jsoncpp object. What I am trying to do is:
void saveAllValues(FIELD **field, Json::Value node, unsigned int* i){
for(Json::ValueIterator it = node.begin(); it != node.end(); it++) {
if ((*it).isObject() || (*it).isArray()) saveAllValues(field, *it, i);
else {
std::string value = field_buffer(field[*i], 0); //get value from ncurses field
*it = Json::Value(value);
(*i)++;
}
}
}
So far this code does nothing. How can I change value of current node?
Upvotes: 2
Views: 3105
Reputation: 385194
This is a C++ typo/misunderstanding, not a JsonCpp problem:
void saveAllValues(FIELD **field, Json::Value node, unsigned int* i){
You took the node by value.
So no changes to it are going to have the slightest effect in the calling scope.
Take a reference to an existing node instead:
void saveAllValues(FIELD **field, Json::Value& node, unsigned int* i){
Upvotes: 2