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

Possibility to use a JsonArray instead of JsonObject in read/update method #326

Open
spyflox opened this issue Jun 19, 2023 · 0 comments
Open

Comments

@spyflox
Copy link

spyflox commented Jun 19, 2023

Actually, I have the following definition:

struct Sensor {
  int value;
  int type;
};
class SensorState {
 public:
  Sensor sensors[4];

  static void read(SensorState& settings, JsonObject& root) {
    for (int i = 0; i < 4; i++) {
      root["value"][i] = settings.sensors[i].value;
      root["type"][i] = settings.sensors[i].type;
    }
  }
...
};

I would like to use a JSON array instead of an object to have code that looks more like this:

class SensorState {
 public:
  Sensor sensors[4];

  static void read(SensorState& settings, JsonArray& root) {
    for (int i = 0; i < 4; i++) {
      root[i]["value"] = settings.sensors[i].value;
      root[i]["type"] = settings.sensors[i].type;
    }
  }
...
};

Do you know how I can do that?
I tried modifying StatefullService to accept arrays, but I confess I'm not proficient enough in C++ to accomplish it.

I love this framework and I congratulate @rjwats once again for creating it.
It would be great in my case if I could pass arrays instead of objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant