Updated Bag of Tricks (markdown)

Gabriele Bellini
2016-07-15 00:50:06 +02:00
parent 1984e11b99
commit e08fe6318a

@@ -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: