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

Iterate through sub items #1102

Closed
johnroper100 opened this issue May 21, 2018 · 5 comments
Closed

Iterate through sub items #1102

johnroper100 opened this issue May 21, 2018 · 5 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@johnroper100
Copy link

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';
    }
@nlohmann
Copy link
Owner

What error did you get?

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label May 22, 2018
@johnroper100
Copy link
Author

So it decided to work for some reason. However, I did get this warning upon compile:

/home/johnroper100/Documents/tonalite2.0/src/tonalite.cpp: In function ‘int processMessage(std::__cxx11::string)’:
/home/johnroper100/Documents/tonalite2.0/src/tonalite.cpp:116:56: warning: ‘static nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::iteration_proxy<nlohmann::detail::iter_impl<nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer> > > nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::iterator_wrapper(nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::reference) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::adl_serializer; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::iteration_proxy<nlohmann::detail::iter_impl<nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer> > > = nlohmann::detail::iteration_proxy<nlohmann::detail::iter_impl<nlohmann::basic_json<> > >; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::reference = nlohmann::basic_json<>&; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::value_type = nlohmann::basic_json<>]’ is deprecated [-Wdeprecated-declarations]
     for (auto& x : json::iterator_wrapper(f["channels"]))
                                                        ^
In file included from /home/johnroper100/Documents/tonalite2.0/src/tonalite.cpp:13:0:
/home/johnroper100/Documents/tonalite2.0/src/json.hpp:14084:38: note: declared here
     static iteration_proxy<iterator> iterator_wrapper(reference ref) noexcept

@nlohmann nlohmann removed the state: needs more info the author of the issue needs to provide more details label May 23, 2018
@nlohmann
Copy link
Owner

The iterator_wrapper is deprecated. Please use the items() member function instead. See https://nlohmann.github.io/json/classnlohmann_1_1basic__json_afe3e137ace692efa08590d8df40f58dd.html#afe3e137ace692efa08590d8df40f58dd for more information.

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels May 23, 2018
@nlohmann
Copy link
Owner

Can I close this issue?

@johnroper100
Copy link
Author

I'm sorry, I just saw this. Yes, it can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants