Skip to content

Iterate through sub items #1102

Description

@johnroper100

I have a json file that looks like this:

{
    "name": "Generic Dimmer",
    "shortName": "Dimmer",
    "manufacturer": "Generic",
    "channels": [
        {
            "type": "intensity",
            "name": "Intensity",
            "max": 255,
            "min": 0,
            "displayMax": 100,
            "displayMin": 0,
            "default": 0,
            "dmxAddress": 0,
            "value": 0,
            "displayValue": 0
        }
    ]
}

I was able to import the file and access props such as name, shortName, and manufacturer, but I'm having trouble looping through the channel array.

This is what I've tried so far:

    ifstream i("../fixtures/"+fixtureName+".json");
    json f;
    i >> f;

    // Create a new fixture from the fixture spec and save it to the fixtures list
    fixture newFixture;
    newFixture.id = randomString();
    newFixture.name = f["name"];
    newFixture.shortName = f["shortName"];
    newFixture.manufacturer = f["manufacturer"];
    newFixture.startDMXAddress = j["startDMXAddress"];
    channel newChannel;
    for (auto& x : json::iterator_wrapper(f["channels"]))
    {
        newChannel.id = randomString();
        newChannel.type = x.value()["type"];
        cout << "key: " << x.key() << ", value: " << x.value() << '\n';
    }

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