Skip to content

Iterating over sub-object #794

Description

@fwsGonzo

I'm sorry but I'm completely lost
I just want to iterate over a value:

    auto tiles = j.find("tiles");
    if (tiles != j.end())
    {
      for (auto tile : *tiles)
      {
        std::cout << tile.key() << std::endl;
        //printf("Name: %s\n", tile.key().c_str());
      }
    }

I even used std::cout just like the examples.

{
  "tiles":
  {
    "a": [2, 5],
    "b": [3, 0],

What am I doing wrong? It says error: no member named 'key' in tile but that makes no sense because im *iterator so I should already be ranged-for-ing over each tile.
The examples also don't really provide any insight into iterating over things like these.

Iterating over the sub-object and then std::cout << tile << std::endl; works like expected, however that is just magic. I want to print the key and the value separately, one as a string and the other as an array using indexing operator.

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

    solution: proposed fixa fix for the issue has been proposed and waits for confirmation

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions