I need to write a function that will take two arguments, a key path and a value, and will populate a JSON object. However, it does not work because the values I'm using are passed by value; I do not know how to refactor the function so pointers are used instead.
This is what I have, it does not produce any error, but it does not update the root
, what do I need to change so that value
is persistent?
void JSONConfig::setValue(string key, Json::Value value)
{
stringstream tokenizer(key);
string token;
string lastToken;
Json::Value node = root;
while (getline(tokenizer, token, '.'))
{
if (!lastToken.empty()) node = node[lastToken];
lastToken = token;
}
if (!lastToken.empty())
{
node[lastToken] = value;
}
}