Skip to content

Error when trying to parse a JSON array #2915

Answered by nlohmann
m4l490n asked this question in Q&A
Discussion options

You must be logged in to vote

You need to define the from_json function in the namespace of the respective type. So please try:

namespace wbid {
void from_json(const nlohmann::json& j,MultiIO &multiIO)
{
    wbid::MultiIOColor color;
    j.at("color").get_to(color);
    multiIO.setColor(color);

    wbid::MultiIOType type;
    j.at("type").get_to(type);
    multiIO.setType(type);

    uint16_t value;
    j.at("color").get_to(value);
    multiIO.setValue(value);
}
}

Also make sure you have conversion functions for all the other types such as wbid::MultiIOColor or wbid::MultiIOType.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@m4l490n
Comment options

Answer selected by m4l490n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants