Skip to content

Updation of child object isn't reflected in parent Object #968

Description

@traw

I've following snippet, where I read and modify child obj attributes with at, But it doesn't get reflected in parent Obj. At the end of following code _root is written to file, But with previoius values of _child["array"].

void fun(std::vector<int> &vec) {
        std::ifstream in(file);
        _root = Json::parse(in);
        in.close();
        if (_root.find("child") != _root.end()) {
            _child = _root.at("child");
            _child["array"] = vec;
          std::ofstream writer(file);
          writer << root;    
        }
}

For example Previous values for _child["array"] were [1, 2] and vec contains [99, 98]. So at the end it should be 99, 98.

Previous Json values:

{
  "child" : {
     "array" : [1, 2]
  }
} 

Expected Json Values:


{
  "child" : {
     "array" : [99, 98]
  }
} 

Am I doing it right?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions