Hi,
I have the following Json data which contains an array of objects/structs:
{ "interaction":2,
"devices": [
{
"id": "7",
"brightness": 100,
"hue": 10000,
"saturation": 254,
"power":true
},
{
"id": "8",
"brightness": 100,
"hue": 10000,
"saturation": 254,
"power":true
},
{
"id": "9",
"brightness": 100,
"hue": 10000,
"saturation": 254,
"power":true
}
]
}
Using @rickkas7 JsonParserGeneratorRK library I want to parse the Json to obtain the devices array and then iterate over the array items. Seems like something simple, but I can’t determine how to instantiate the array correctly to assign it a value.
void runInteraction(String commands){
jsonParser.clear();
jsonParser.addString(commands);
deviceArray[] = {}; //how do I instantiate this
jsonParser.getOuterValueByKey("devices", deviceArray);
for( unsigned int i = 0; i < sizeof(deviceArray)/sizeof(deviceArray[0]); i++ ){
Serial.println(deviceArray[i].power);
}
}
C++ is a new language for me, so still wrapping my head around the data types and their differences compared to other languages. Thanks.