mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-25 08:17:32 +02:00
* Removed `ArduinoJson::String` * Removed `JsonVariant::defaultValue<T>()` * Removed non-template `JsonObject::get()` and `JsonArray.get()` * Fixed support for `StringSumHelper` (issue #184) * Replaced `ARDUINOJSON_USE_ARDUINO_STRING` by `ARDUINOJSON_ENABLE_STD_STRING` and `ARDUINOJSON_ENABLE_ARDUINO_STRING` (issue #378) * Added example `StringExample.ino` to show where `String` can be used
63 lines
1.4 KiB
C++
63 lines
1.4 KiB
C++
// Copyright Benoit Blanchon 2014-2016
|
|
// MIT License
|
|
//
|
|
// Arduino JSON library
|
|
// https://github.com/bblanchon/ArduinoJson
|
|
// If you like this project, please add a star!
|
|
|
|
#pragma once
|
|
|
|
#include "JsonArray.hpp"
|
|
#include "JsonArraySubscript.hpp"
|
|
#include "JsonObject.hpp"
|
|
|
|
namespace ArduinoJson {
|
|
|
|
inline JsonVariant::JsonVariant(const JsonArray &array) {
|
|
if (array.success()) {
|
|
_type = Internals::JSON_ARRAY;
|
|
_content.asArray = const_cast<JsonArray *>(&array);
|
|
} else {
|
|
_type = Internals::JSON_UNDEFINED;
|
|
}
|
|
}
|
|
|
|
inline JsonVariant::JsonVariant(const JsonObject &object) {
|
|
if (object.success()) {
|
|
_type = Internals::JSON_OBJECT;
|
|
_content.asObject = const_cast<JsonObject *>(&object);
|
|
} else {
|
|
_type = Internals::JSON_UNDEFINED;
|
|
}
|
|
}
|
|
|
|
namespace Internals {
|
|
template <>
|
|
struct JsonVariantDefault<JsonArray> {
|
|
static JsonArray &get() {
|
|
return JsonArray::invalid();
|
|
}
|
|
};
|
|
}
|
|
|
|
inline JsonArray &JsonVariant::asArray() const {
|
|
if (_type == Internals::JSON_ARRAY) return *_content.asArray;
|
|
return JsonArray::invalid();
|
|
}
|
|
|
|
inline JsonArray &JsonArray::createNestedArray() {
|
|
if (!_buffer) return JsonArray::invalid();
|
|
JsonArray &array = _buffer->createArray();
|
|
add(array);
|
|
return array;
|
|
}
|
|
|
|
template <typename TString>
|
|
inline JsonArray &JsonObject::createNestedArray(const TString &key) {
|
|
if (!_buffer) return JsonArray::invalid();
|
|
JsonArray &array = _buffer->createArray();
|
|
set(key, array);
|
|
return array;
|
|
}
|
|
}
|