Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot update json data in an iterator? #1947

Closed
McSwan opened this issue Feb 18, 2020 · 1 comment
Closed

Cannot update json data in an iterator? #1947

McSwan opened this issue Feb 18, 2020 · 1 comment

Comments

@McSwan
Copy link

McSwan commented Feb 18, 2020

Can't seem to change a variable in an iterator or I don't know how to do properly.
Here's what I've tried

json j;

  j["Callback"] = Callback;
  j["CallbackCalled"] = false;

  cout << j.dump() << endl;
  Updating.push_back(j);

...

for (auto it = Updating.begin(); it != Updating.end(); ++it)
  {
          if (!it.value()["CallbackCalled"])
          {
              RunCallback(it.value()["Callback"]);
             //(*it)["CallbackCalled"] = true;  // no!
             //cout << (*it).dump(); // no!
             // auto obj = (*it).find("CallbackCalled");
             // obj.value() = true; // no!
             // Updating["0"]["CallbackCalled"] = true; //no!

             //(*it).emplace("CallbackCalled", true); // no!
             //json j = json::parse((*it).dump());
             //j["CallbackCalled"] = true; // no!

          }

How do I set (*it)["CallbackCalled"] = true; ?

Thanks!

@McSwan
Copy link
Author

McSwan commented Feb 18, 2020

My bad - The callback function was doing a push_back while it was iterating, which invalidated the iterator

@McSwan McSwan closed this as completed Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant