Parameters file defines the creation of entities and stored in flash. Its structure is given, and all fields ( keys & values ) are given.In current phase - those parameters are hard-coded in aconst char* cont_params, as shown below.
My goal, is when array is empty, for exampleRF_2entity - means that current MCU does not uses its RF abilities, and will not init any RF entities. The wayRF_2entity is defined below, as empty array,[] , ArduinoJSON'sisNull() function return0 in that case.
How can I keep parameters file's structure and logic, rather that fill its values with255 for example.
Serial.begin(115200); StaticJsonDocument<1200> doc; const char *cont_params = "{\"entityType\": [1,1,1,1],\ \"SWname\": [\"SW_0\",\"SW_1\",\"SW_2\",\"SW_3\"],\ \"SW_buttonTypes\": [2,1,1,1],\ \"SW_timeout\": [10,11,12,13],\ \"SWvirtCMD\":[0,0,0,0],\ \"Winname\": [],\ \"WextInputs\": [],\ \"WinvirtCMD\":[],\ \"RF_2entity\": [],\ \"v_file\": 0.5}"; DeserializationError err = deserializeJson(doc, cont_params); JsonArray array = doc["Winname"].as<JsonArray>(); serializeJsonPretty(array,Serial); Serial.println(array.isNull());output:
[]0- sorry, but I don't understand the question. what is the problem? isNull() returned 0 (false), not 1 (true)2023-06-02 05:08:55 +00:00CommentedJun 2, 2023 at 5:08
- @Juraj - Question edited. you are right....
isNull()returns that array is not empty.guyd– guyd2023-06-02 05:18:34 +00:00CommentedJun 2, 2023 at 5:18
1 Answer1
The methodisNull() is not what you want. It tells you whether the instance holds an array at all or not. And of course, your specific instance holds an array, though an empty one. Therefore, the method correctly returnsfalse, aka0.
Asthe API documentation shows, there are more methods to use.
What you want issize(), which returns the number of elements in the array. It will even return0 on an instance without an array.
- in that case,
doc["Winname"].size()will suffice. I don't really need to use an array.guyd– guyd2023-06-02 06:47:48 +00:00CommentedJun 2, 2023 at 6:47
Explore related questions
See similar questions with these tags.

