diff --git a/Bag-of-Tricks.md b/Bag-of-Tricks.md index c9d912a..4e0628f 100644 --- a/Bag-of-Tricks.md +++ b/Bag-of-Tricks.md @@ -1,5 +1,29 @@ Here are helper class that can help you add missing features. +## Extract an array of integer + +Suppose we have an input like this: + +```json +{"leds":[56,60,46]} +``` + +And we want to get a `int[]` out of it: + +```c++ +#define MAX_LED_COUNT 10 + +int leds[MAX_LED_COUNT]; +int ledCount = 0; + +for(int led : root["leds"].asArray()) { + leds[ledCount++] = led; + if (ledCount >= MAX_LED_COUNT) break; +} +``` + +See issue [#246](https://github.com/bblanchon/ArduinoJson/issues/246) + ## Buffered output: Here is a proxy that will put bytes in a buffer before actually writing them to the destination: