mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-09-26 06:50:56 +02:00
Updated Bag of Tricks (markdown)
@@ -1,5 +1,31 @@
|
||||
Here are helper class that can help you add missing features.
|
||||
|
||||
## Look for a nested key
|
||||
|
||||
Suppose we've this json:
|
||||
|
||||
```json
|
||||
{"key1":1,"key2":{"subkey1":3,"subkey2":4}}
|
||||
```
|
||||
|
||||
And we want to check presence of **subkey1** (or **subkey2**). Using **containsKey** method will not work, since **subkey1** and **subkey2** are nested keys inside **key2** value. This function allows to find key presence even if they are nested inside any key value:
|
||||
|
||||
```c++
|
||||
bool containsNestedKey(const JsonObject& obj, const char* key) {
|
||||
for (const JsonPair& pair : obj) {
|
||||
if (!strcmp(pair.key, key))
|
||||
return true;
|
||||
|
||||
if (containsNestedKey(pair.value.as<JsonObject>(), key))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
```
|
||||
|
||||
See issue [#322](https://github.com/bblanchon/ArduinoJson/issues/322)
|
||||
|
||||
## Extract an array of integer
|
||||
|
||||
Suppose we have an input like this:
|
||||
|
Reference in New Issue
Block a user