From d41eee47fe2fa79d5259a7de895081c338a6b2f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Blanchon?= Date: Tue, 22 Mar 2016 10:59:39 +0100 Subject: [PATCH] Updated Bag of Tricks (markdown) --- Bag-of-Tricks.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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: