Skip to content

Question - how to find an object in an array #1331

Closed
@SimplyLiz

Description

@SimplyLiz

I want to store multiple images (with different attributes) per tile-type and find the correct json object that matches a key.
like:

Type floor, orientation: center

for (auto it : TileDataJSON["floor"].items()) {
  cout << "key " << it.key() << " and val " <<it.value();

}

Output:

key 0 and val {"image":"floor_0.png","orientation":"flat"}
key 1 and val {"image":"floor_center.png","orientation":"center"}
key 2 and val {"image":"floor_n.png","orientation":"n"}
....

Which makes sense.

If i try to access
TileDataJSON["floor"][it.key()]
i get an exception. ( i think it's because it.key is a string an not an int...

My (simplified) JSON File looks like this:

  "floor": [
    {
      "image": "floor_0.png",
      "orientation": "flat"
    },
    {
      "image": "floor_center.png",
      "orientation": "center"
    }
  ]
}```

What is the correct way to find the correct object of a type by an attribute?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions