SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
json.h
Go to the documentation of this file.
1#ifndef SENSESP_SRC_SENSESP_TYPES_JSON_H_
2#define SENSESP_SRC_SENSESP_TYPES_JSON_H_
3
4#include <vector>
5
6#include "ArduinoJson.h"
7
8namespace ArduinoJson {
9template <typename T>
10struct Converter<std::vector<T> > {
11 static void toJson(const std::vector<T>& src, JsonVariant dst) {
12 JsonArray array = dst.to<JsonArray>();
13 for (T item : src) array.add(item);
14 }
15
16 static std::vector<T> fromJson(JsonVariantConst src) {
17 std::vector<T> dst;
18 for (T item : src.as<JsonArrayConst>()) dst.push_back(item);
19 return dst;
20 }
21
22 static bool checkJson(JsonVariantConst src) {
23 JsonArrayConst array = src;
24 bool result = array;
25 for (JsonVariantConst item : array) result &= item.is<T>();
26 return result;
27 }
28};
29} // namespace ARDUINOJSON_NAMESPACE
30
31#endif // SENSESP_SRC_SENSESP_TYPES_JSON_H_
static void toJson(const std::vector< T > &src, JsonVariant dst)
Definition json.h:11
static bool checkJson(JsonVariantConst src)
Definition json.h:22
static std::vector< T > fromJson(JsonVariantConst src)
Definition json.h:16